Any help I can get with program design and such would be great, you can learn code all day but until you use it it is hard to figure out how to structure a larger program.
I am writing a (kinda) simple program that does the following: Helps a user create items, add them to a meal, and then put meals and items on a grocery list that can help with shopping. Obviously that is way dumbed down. So the user won't have to retype in items every time the master list of items, meals, and grocerylists are all saved to the HD using serialization for the time being.
Here is my basic design and some reasons behind it: I am trying to seperate all the functionality out to individual parts and keep loose coupling (I emphasize the
word "trying"). This is hard to put into text so bare with me.
- First I created an abstract class called Listable which is any object that is allowed to be added to a GroceryList.
- A GroceryList is basically a glorified HashMap which accepts a
String as key and a Listable as the value.
- A GroceryList will hold Meal and Component objects.
- A Meal is basically a glorified Set of Items.
- An Item is just a Component + a quantity.
- And finally a Component is just a few fields like name, cost, etc that represents something you would buy at the store.
So basically:
- A GroceryListManager HAS-A GroceryList<Listable>, a Set<Meal>, and a Set<Component>.
- Meal extends Listable and HAS-A Set<Item>
- Item extends Component
- Component extends Listable
- and finally Listable implements Serializable
The reason I have a Component and an Item is that I want to save a Component which may have data like: name = "Sausage", section = "meat", cost = 2.50f, etc and I want to save that information without saving quantity = 3lb, which only makes since in a meal. Therefor I keep a master list of Components which are in a Set (unique by name) and only have Items data saved to the HD inside of a Meal (where a quantity makes since). I also keep GroceryList as a HashMap because since I am adding different types of Listables and they are not mutually comparable I can't use a Set and I want to add/remove items based on their name so I use that as the key values.
I think I did a pretty bad job describing my code, lol. I also left out as much as I could that I don't think makes as much difference. For example a bunch of enum classes with methods, a persistance layer controller object, the consol/user interface controller, etc. I am most concerned with the structure of my business logic and have reformed it 3-4 times wasting huge amounts of time and I still feel that it is wrong and certain parts are forced into working. I'm sure once I press post I will think of 10 things I forgot to mention, so please ask questions, lol.
Any and all help is appreciated. I think this will help me become a better coder more than anything else.