aspose file tools*
The moose likes Beginning Java and the fly likes object-design question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "object-design question" Watch "object-design question" New topic
Author

object-design question

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38412
    
  23
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: object-design question