This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I have a program and I need it to be incredibly modular. It needs to be able to store data of data type that will be determined by an XML after the program's running. How could I do this?
One idea I had was to make an array of objects and save them in that, but I want to know if there's a better way?
2. Have all the types you'll be using implement a common interface, and declare it as that type.
3. Have different code branches using if or switch or the Command Pattern that have Java code declaring it to be of the appropriate type.
It's hard to be any more detailed without more specifics about your requirements beyond, "I want it to be flexible."
Joined: Mar 11, 2012
It's all going to be primitive data types (or their respective classes).
I really need this to be very flexible so I'm sorry I can't give a lot of information, but I think just declaring them as object will work. Thanks.
Here's the thing about programming and programmers - we are INCREDIBLY literal. If you say "it has to be a primitive", then we assume that is what you mean. When you then come back and say "well, it doesn't have to be a PRIMITIVE primitive", we tend to feel like you are wasting our time.
If the values have to be numeric, then say they have to be numeric - don't say they have to be primitives, as that has a VERY specific meaning.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors