|
|
On 4/5/2011 9:06, Tom Austin wrote:
> Given the example, do you have any suggestions as how they should be stored?
The example isn't really detailed enough for me to say.
The Java collection framework gives you a bunch of interfaces for things
like lists, maps, sets, bags, etc. It then gives you a bunch of concrete
implementations like lists-based-on-arrays, maps-based-on-hashtables,
maps-based-on-trees, etc.
Without knowing how you expect to access the sub-collections, it's hard to
say whether you have a bag of balls, a list of balls, or a map of balls, for
example. Are you going to look up balls by name? Do you need to know what
order they are in?
It looks to me that everything you described as "collection of ..." should
be a class from the collections framework, and the other stuff should be
your own classes. In other words, based on what you wrote, I wouldn't expect
you to declare any class of your own as implementing any of the collection
interfaces.
class playground {
public Set<ball> balls;
public Set<kid> kids;
public Set<bat> bats;
}
class kid {
public List<shoe> shoes;
// shoes[0] is left shoe, shoes[1] is right shoe
}
--
Darren New, San Diego CA, USA (PST)
"Coding without comments is like
driving without turn signals."
Post a reply to this message
|
|