W
why-em-jay
Hi,
My title is probably not clear, here it goes:
I have package A and I have created an object from that package in my
main prog.
This object has properties, and one of them is a new object from
package B.
Afaik, this is the HAS-A relationship.
Now my issue is to call a method from package A from within a method in
package B...
I could give the object (created off package A) as an argument, but I
guess there might be a nicer way to achieve that ? or my design is
crappy ??
Ex:
in main prog:
--------------
$obj = Server->new();
$obj->createSession();
$obj->doSomething();
in package Server:
-------------------
sub createSession {
my $self=shift;
$self->{session} = new Session();
}
sub doSomething {
my $self=shift;
$self->{session}->doTask();
}
sub returnServerDetails {
my $self = shift;
# here i return a property of the created object ($obj)
return $self->{one_property};
}
in package B:
--------------
sub doTask {
my $self =shift;
# here i want to call server::returnServerDetails, but i want it
to be
# aware that i'm talking about the object that created me ($obj)
# because i need some properties about the Server that
# created me... and I need to call several methods from package
Server
# which will return info about it.
}
Thanks for your help !
regards,
why-em-jay
My title is probably not clear, here it goes:
I have package A and I have created an object from that package in my
main prog.
This object has properties, and one of them is a new object from
package B.
Afaik, this is the HAS-A relationship.
Now my issue is to call a method from package A from within a method in
package B...
I could give the object (created off package A) as an argument, but I
guess there might be a nicer way to achieve that ? or my design is
crappy ??
Ex:
in main prog:
--------------
$obj = Server->new();
$obj->createSession();
$obj->doSomething();
in package Server:
-------------------
sub createSession {
my $self=shift;
$self->{session} = new Session();
}
sub doSomething {
my $self=shift;
$self->{session}->doTask();
}
sub returnServerDetails {
my $self = shift;
# here i return a property of the created object ($obj)
return $self->{one_property};
}
in package B:
--------------
sub doTask {
my $self =shift;
# here i want to call server::returnServerDetails, but i want it
to be
# aware that i'm talking about the object that created me ($obj)
# because i need some properties about the Server that
# created me... and I need to call several methods from package
Server
# which will return info about it.
}
Thanks for your help !
regards,
why-em-jay