This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

object-design question

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have something like this:



So you see, In one State-Object, I can have one ore more States-Objects.

Is this a good desing or should I avoid such things and use a extended class of States or something else?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without knowing the domain in which this might be used, it is unclear. I will say to me, it seems odd. Usually, when an object contains a collection of itself, there is a parent/child relationship. For example, a Category object having a collection of Category objects where the collection is children of the parent. So it kind of depends on how you are using State in your application.
 
Campbell Ritchie
Sheriff
Posts: 48448
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to work out your design depending on what you plan to do with this class. It does seem peculiar that you have a Set<State> inside its own class, however.

Do you really want each State to have references to other states? That may mean a lot of Sets with a lot of references in each.
Do you want the Set to be shared between all the States? In which case it should be labelled static and (probably) instantiated in a static initialiser block.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic