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} );
In reply to Proper way to create 'globals' by zaven
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |