Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 3
    I'd call this approach "Horrible", frankly. Strings are a terrible key for data, they're easily typoable and any issues with them are only thrown up at runtime. If for some reason you cannot use properties, I see no downside to having a dictionary of SomeEnum -> Object, which still sucks due to losing type safety on one end, but gains a very little back on the other. Commented Nov 7, 2013 at 14:19
  • @Phoshi yes, this is essentially taking a dynamic language approach and applying it to a statically typed language, so you sacrifice static typing for extensibility. Commented Nov 7, 2013 at 15:01
  • 1
    Except that there are better ways to achieve this sort of flexibility that don't end up killing type safety quite so bad, and I'm not sure what benefit you're getting here other than it being quicker to develop that component. Now, if there aren't many other components, that's totally valid, but losing type safety in your data storage engine is insane in a larger project. At best, you're going to litter your code with instanceof and (Casting). Commented Nov 7, 2013 at 15:50
  • No, it's instanceof that this approach eliminates since there are no derived types any more. I didn't want to bloat the question with long details about why I'm interested in this approach, but a big part of the driver is getting rid of instanceof, and dealing with the challenges of needing to deserialize objects from any previous (or future) version of the application. Commented Nov 7, 2013 at 15:58
  • If you're never doing runtime typechecks then you can only sanely treat everything as "object". I mean, I guess you can treat everything as strings if you ToString everything before use, but this is still all of the disadvantages of loosely typed programming without the metadata that actually makes that work. Treating everything as Object and never changing types isn't making the type system more flexible, it's making the type system work against you for no benefit. Commented Nov 8, 2013 at 9:24