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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "object-design question" Watch "object-design question" New topic

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: 15302

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

Joined: Oct 13, 2005
Posts: 46349
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.
I agree. Here's the link:
subject: object-design question
It's not a secret anymore!