zaven has asked for the wisdom of the Perl Monks concerning the following question:
I have created a hierarchy of classes in OO style for a testing program. At the top of the hierarchy is the TestSuite class, which creates several other types of objects, and these new objects will each create several others, etc. Everything is ultimately spawned by the TestSuite, since it is created first. However, most objects do not have an IS-A relationship with TestSuite.
My question is this: if I have a hash of globally useful information in a TestSuite instance object, how can I make this hash accessible by any object that happens to be created by a TestSuite, without passing it as a method parameter to every new object created by TestSuite? Or, if it is already accessible, how do I properly access it from one of the secondary or tertiary objects? For example:
In other words, what's the best way for Blob::print_stuff() to access $ts->{info} if we assume Blob::print_stuff() is always called from a method of TestSuite? much thanksmy $ts = new TestSuite(); # $ts->{info} is now defined $ts->make_a_blob(); # $ts->{blob} is now a ref to an object of type Blob $ts->print_blob() # Calls $self->{blob}->print_stuff(); # I want the method Blob::print_stuff() to access information in $ts-> +{info} #I want to avoid doing this: $ts->{blob}->print_stuff( $ts->{info} );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Proper way to create 'globals'
by kyle (Abbot) on Feb 07, 2007 at 21:54 UTC | |
by zaven (Sexton) on Feb 07, 2007 at 22:51 UTC | |
|
Re: Proper way to create 'globals'
by Tanktalus (Canon) on Feb 07, 2007 at 21:09 UTC | |
|
Re: Proper way to create 'globals'
by chromatic (Archbishop) on Feb 08, 2007 at 00:32 UTC | |
by Beechbone (Friar) on Feb 08, 2007 at 08:35 UTC | |
by chromatic (Archbishop) on Feb 08, 2007 at 20:16 UTC | |
|
Re: Proper way to create 'globals'
by adrianh (Chancellor) on Feb 08, 2007 at 12:33 UTC | |
|
Re: Proper way to create 'globals'
by Moron (Curate) on Feb 08, 2007 at 10:41 UTC | |
|
Re: Proper way to create 'globals'
by dragonchild (Archbishop) on Feb 09, 2007 at 01:47 UTC | |
|
Re: Proper way to create 'globals'
by bsdz (Friar) on Feb 08, 2007 at 18:35 UTC |