0

I've got a problem with some designing in my code. I'm currently writing a prototype for a game in Java but I'm not confortable with the choices I've made. Currently my game has a couple of classes: Circle, CircleSet and Component ( the main class basically ). The relationships between these classes are the following: 1 CircleSet can have multiple Circles and every Circle needs to know in what CircleSet it's in.

Can someone help me with some examples of collections and what suits best for me?

Thanks in advance!

  • 3
    Does `Circle` impelement `equals()`? If so, can `CircleSet` contain two `Circle` objects `a` and `b` such that `a.equals(b)`? If not, then `Set` is probably a good choice based on the name `CircleSet`. – Code-Apprentice Jun 01 '13 at 18:23

1 Answers1

1

Intodudec a CircleSet id in your CircleSet class. Add the set of circles in your CircleSet class as

Set <Circles> = new HashSet<Circles>();

In component class, create a hashmap containing mapping of circleSetId and set of Circles as mentioned here:

Map <String,HashSet> circlSetMapping = new HashMap<String,HashSet>();

Hope it helps!

Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136