Object taking an object

Started by
1 comment, last by dmatter 14 years, 7 months ago
I'm trying to wrap my head around OOP and I was trying to create a simple program out of OOP. What I'm creating is a simple recipe box program. I have split it up into three objects as follows: Recipe Box: contains recipes files, can sort them by fields. Recipe Card: contains recipe itself and information Food List: takes text fields and orders them in sets to print out to paper My problem is that recipe box needs to take a recipe object or at the very abstract a card object. Am I planing this out wrong? should one class depend on another, I didn't think it should but I don't see a way around this yet? Any help or advice would be very great.
Do or do not there is no try -yoda
Advertisement
It doesn't look wrong to me.. Having objects contain objects is not bad. In this case I think it is useful to have RecipeBox contain recipes.
J.W.
A Recipe Box is a "collection" of Recipes, it needs to know about Recipe objects in order to contain them, that's fine. Components have dependencies on other components, that's perfectly normal. It's possible to reduce coupling through various constructs like interfaces but you're still dependent on the interface.

The only thing there that looks a little squiff is the Food List, its description mentions nothing about food, so it sounds as if its name is overly specific. Could it really be more generically named, a Page Layout, or some such?

This topic is closed to new replies.

Advertisement