zxViperxz has asked for the wisdom of the Perl Monks concerning the following question:
The way this works I can declare all my parameters for respective objects and reuse them again without wasting new declarations, and modify them between different objects, e.g.my $object1 = new MyClasses::Object1 ( _cgi => new CGI, param1 => '...', param2 => '...', ); $object1->dothis; my $object2 = new MyClasses::Object2 ( _object1 => $object1, param1 => '...', param2 => '...' ); $object2->setsomething; my $object3 = new MyClasses::Object3 ( _object1 => $object1 ); $object3->blah;
After looking at a bunch of modules and other perl code I have realised I have made an error by making object argument names _object seeing that is is against the private variable declaration (however I really like my convention seeing that I can tell an object and a normal argument apart).Inside Object2: sub setsomething { my $self = shift; $self->{_object1}->{mode} = 1; } Inside Object3: sub blah { my $self = shift; if ($self->{_object1}->{mode}){ return $self->{_object1}->{_cgi}->param('blah'); } else { return $self->{_object1}->{_cgi}->param('pleh'); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Conventions with Passing Objects to Objects
by diotalevi (Canon) on Jan 13, 2006 at 14:43 UTC | |
by zxViperxz (Acolyte) on Jan 13, 2006 at 20:59 UTC | |
by diotalevi (Canon) on Jan 16, 2006 at 15:24 UTC | |
|
Re: Conventions with Passing Objects to Objects
by xdg (Monsignor) on Jan 13, 2006 at 14:18 UTC | |
|
Re: Conventions with Passing Objects to Objects
by derby (Abbot) on Jan 13, 2006 at 14:20 UTC | |
|
Re: Conventions with Passing Objects to Objects
by jhourcle (Prior) on Jan 14, 2006 at 04:42 UTC | |
|
Re: Conventions with Passing Objects to Objects
by Anonymous Monk on Jan 17, 2006 at 17:03 UTC | |
by zxViperxz (Acolyte) on Jan 20, 2006 at 06:36 UTC |