question of code design part II

perhaps someone will remember my (now deleted) post. i didnt know that crossposting is punished so hard, but i got my lesson.

little summary:

i have a game and a GameManager class. the manager holds a bunch of (game)objects. the problem is, that sometimes the gameobjects need to notify the manager about changes. i see a bad style in passing every little object a reference of the GameManager, but have no good idea, how to avoid permanent questions the GameManager if it needs to change a status of an object (e.g. are you dead/exploded ?).

someone suggested the observer-pattern. i know this interface-pattern but i noticed it as an elegant way of passing multiple references.

it would be very nice if i could set new life to this topic.

[771 byte] By [Serethos_0a] at [2007-9-29 16:20:25]
# 1
Use a static singleton pattern.Or pass a reference to each Game object (what's wrong with that?).
JN_a at 2007-7-15 14:36:26 > top of Java-index,Other Topics,Java Game Development...
# 2

Implement bound properties.

Any object then wishing to listen for changes can easily.

PropertyChangeListener

PropertyChangeEvent

PropertyChangeSupport

Take a look here:

http://java.sun.com/docs/books/tutorial/javabeans/properties/bound.html

...and maybe here:

http://java.sun.com/docs/books/tutorial/uiswing/events/propertychangelistener.html

rkconnera at 2007-7-15 14:36:26 > top of Java-index,Other Topics,Java Game Development...