Win a copy of Functional Reactive Programming this week in the Other Languages 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
Ranch Hand
Posts: 15304
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
Pie
Posts: 50263
79
  • 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