I have a query about messaging objects which have been instantiated within a different object.
Specifically I want to keep my ‘gamestate’ object separate from my ‘GLview Object’ and be able to call methods belonging to each object from within the other.
What is the best way of achieving this?
Thanks in advance 😉
There are several ways of achieving this.
The most obvious is that your superclasses may be defined with properties referencing their properties (sub-objects, as you’re describing). Eg, [[gamestate subObject] doSomething], where ‘subObject’ is a synthesized property pointing to the object you want to message.
If you want looser coupling, consider using a pattern of delegation or registering for notifications.
Your nestled objects may define a delegate protocol, calling it’s delegate methods at appropriate times. If another object conforms to the protocol and is assigned as the delegate, it will receive the messages.
Finally, objects can register for notifications. Object A can post notifications (e.g., ‘something happened’), and Object B can register to for notifications (e.g., perform method X when you’re notified ‘something happened’).