How do I give all objects access to all the other objects?

edited November 2016 in How To...

I have a SuperCreature class which is extended by a creature (currently only one, called Shy). I want all the Shy objects to be aware of all the other SuperCreatures so they can avoid them, hence their name. How would I do that? I have a CreatureManager class as well that is primarily an arraylist of SuperCreatures with some handy management things so it's only one line to update all the creatures and things of that nature. I considered giving every SuperCreature a copy of the manager but that would cause recursion issues as well as be difficult to update. I also tried just giving all of them an arrayList of other SuperCreatures which is a little easier to keep up to date but a similar problem occurs. Thank you for your time!

Tagged:

Answers

  • Answer ✓

    The best way would be for the CreatureManager class to supervise the creature-creature interactions since it is aware of all the creatures. In the Creature class you have a method that has a single parameter of type SuperCreature to perform the actual interaction if any.

Sign In or Register to comment.