really either. if "called", the called method would be a factory method,
which would at some point set the appropriate calling object parameter...
and if "constructed" the constructor would include nearly the same line.
so basically, if in a factory "called" method which has been called by a
method in object x, a new object y is created and the correct parameter in
y is set through something like this:
y.parentObject = x
(but without passing x (as a parameter set to value "this") from x, i
don't know how to get a reference to x)
if done in a constructor for y:
this.parentObject = x
but same problem again.
the reason i don't want to have people pass the parent object as a
parameter is it opens the door for incorrect objects to be passed... that
is let us assume that the constructor option is used and the constructor
includes a parameter for identifying the parent object... so from within x
there is a line in a method like so:
yClass y = new yClass(this);
that would work, but someone could also then do this:
yClass y = new yClass(z);
where z is some other object, possibly of the same class as x (so checking
the class of the object isn't enough to catch the problem).
i want to guarantee that the parentObject reference in y correctly points
to x by doing it automatically.
thanks again,
murat
On Mon, 12 Jan 2004, nos wrote:
"Murat Tasan" <ta***@eecs.cwru.edu> wrote in message
news:Pine.SOL.4.53.0401121353170.947@zoidberg... i have a quick question... is there a way to obtain the reference to the
object which called the currently executing method?
here is the scenario, i have a class and a field which i would like to
populate with a reference to the object that constructed this current
object. i would attempt to accomplish this by setting the appropriate
field from within the constructor...
Constructed or called?
i figured it might be obtainable from the stack trace, but that doesn't
seem to work.
oh, and i do know that i could just add an extra parameter to the
constructor and from the calling method just pass "this", but i don't want
to have to trust that the people using my code will actually do this
correctly each time.
thanks for any input,
murat
--
Murat Tasan
mx**@po.cwru.edu
ta***@eecs.cwru.edu
mu*********@cwru.edu
http://genomics.cwru.edu
--
Murat Tasan
mx**@po.cwru.edu ta***@eecs.cwru.edu mu*********@cwru.edu http://genomics.cwru.edu