users
[Top] [All Lists]

Re: [cinjug-users] Calling methods of sibling objects

To: "Rich Schramm" <richard.schramm@xxxxxxxxxxxxxxxxxx>
Subject: Re: [cinjug-users] Calling methods of sibling objects
From: "Keshav Kode" <keshav.kode@xxxxxxxxx>
Date: Sat, 18 Aug 2007 01:06:23 -0400
Cc: users@xxxxxxxxxx
Delivered-to: mailing list users@xxxxxxxxxx
Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=cF1XIKCMOjF7/IClF+42ovK7IXDGhz9NmGlWVpVqD7D67QMB80w7+8iDCRqQOeuehZx10YKHnIn+GM4uHe/A2usguAFkJ8IhBVTR9IlmElvFWa4D+dT7aYEc52Fwv36kBjakG3jPB4GJzpPMki3R7swsg3Eem5yysz1Xi0fDsuA=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=UvxMWcNN06bwUmW8cqPKA9cpvc1Fsz0sH5fPe2kthZ8XIEf6EGKxGnhuih7KwxK1Ap0DTS4r2pk2xWkAJVmDek9IYXWn6g7vvLskzAhVeCZ8Dsj959/d5E7pYDvUNxoykkxb5ZkoEZHN7qafFFQ7MgOnLJwiBA2gWYKW507XSuM=
In-reply-to: <BCDB7761EF65A54B92F46CD400D1D2D96330F5@xxxxxxxxxxxxx>
Mailing-list: contact users-help@xxxxxxxxxx; run by ezmlm
References: <BCDB7761EF65A54B92F46CD400D1D2D96330F5@xxxxxxxxxxxxx>

Rich,

 

One way to do this is to make 'Smart Child' object. What I mean is in each child object keep sibling reference. Getter & setter in Parent object maintain this sibling references. So at any point in time each child knows who is its sibling object and can invoke method directly.

 

Overall, you have to take this pain either ways. Either you do work ahead of the time when building the tree or you do work while method invocation. The design decision will depend on how many times the method is called in given business scenario and how many times you change the object relations.

 

Parent

     +--- Child1 child_1    getter / setter

     +--- Child2 child_2    getter / setter

 

Child1

     +--- Child2 sibling     getter / setter

     +--- Other Child1 attributes

     +--- method1()

 

Child2

     +--- Child1 sibling     getter / setter

     +--- Other Child2 attributes

     +--- method2()

Another approach could be that you externalize this relationship management and create RelationShipManager class. Sole purpose of this Class is to manage object relationship. Anytime you set or remove child call this manager and you query this manager for any object in the tree. Again it depends on how sophisticated you want to be in your design.

Hope this helps.

 

Keshav.

 


 
On 8/17/07, Rich Schramm <richard.schramm@xxxxxxxxxxxxxxxxxx> wrote:

Hi,

 

Hoping this is not a dumb question, maybe someone call help.

 

The object model for my application contains a parent object (Parent) that has two other objects as properties (child1 and child2).  In child1, there is a method (method1) that I want to call from child2.  However, I am stumped on how to get a handle to child1 or even the parent from within child2 without having to pass a reference to child2 from a method in parent.  Is there a way to call parent.child1.method1() from within parent.child2?

 

Thanks,

 

Richard Schramm
Supply Dynamics, LLC.
513.965.2000 x14 (office)
513.300.7851 (mobile)

http://www.supplydynamics.com/

 




--
Thank you,
Keshav Kode
Keshav.Kode@xxxxxxxxx
<Prev in Thread] Current Thread [Next in Thread>