Re: Newbie: OOP Question: messaging Objects
Re: Newbie: OOP Question: messaging Objects
- Subject: Re: Newbie: OOP Question: messaging Objects
- From: Sherm Pendley <email@hidden>
- Date: Wed, 16 Apr 2003 17:43:42 -0400
On Wednesday, April 16, 2003, at 02:50 PM, Bernd Homuth wrote:
Here we go: I4m creating a bunch of objects like a tree. The root is my
main NSDocument subclass. In the roof I4m creating some little leaf
Object which needs to go all the way down to the root.
My question: Once the Object is created am I supposed to send a
notification and the NSDocument subclass gets the Object or is there
another way?
I mean in some cases objects create objects and those objects don4t
know who asked for their creation (or do they) so I can4t send them
back the way they are coming from.
I suggest that each leaf object should keep an instance variable that
points to its tree object. When a leaf needs to create a new leaf, it
would then know what tree to pass the newly-created leaf to. When a tree
object is passed a leaf to add to itself, it should call the leaf's
-setTree method so that the leaf knows to what tree it belongs.
If a tree other than an object's parent tree can ask it to create a new
leaf, you could pass a pointer to the tree making the request as part of
the "createNewLeaf" method.
Notifications would work, but it would be expensive. Upon creating a new
leaf, an object would fire off an "CreatedANewLeaf" notification. Each
tree object would then need to respond to this notification by walking
through its own leaves, to find if the leaf that fired the notification
belongs to it.
sherm--
If you listen to a UNIX shell, can you hear the C?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.