newbio has asked for the wisdom of the Perl Monks concerning the following question:
I have just started learning perl and OOPs concepts. I have a query regarding perl OOP concept.
Below is a standard piece of code showing class implementation. I understand with limited knowledge that $self is a reference to a hash, and this hash gets converted to an object after getting blessed. Blessing essentially means that the $self hash can now use any function in XYZ class for manipulation. Please correct me if I am wrong anywhere.
I have mostly come across examples where constructor function, such as "new" here contains a hash that gets blessed within the constructor. Many a times this hash may be nested to form a complex data structure. However, suppose instead of having one complex hash structures I choose to have two simple hash structures (say $self1 and $self2) . My question is, can we have two hashes (say $self1 and $self2) and both being blessed with the same class within the constructor. Is this allowed? If yes, then do $self1 and $self2 form two separate objects after being blessed. How then are $self1 and $self2 connected/related in anayway? Also, what are advantages of having a complex single hash vis a vis two simple hashes? I am actually confused. I guess I am missing something here.
Please advise.
Thanks,
package XYZ; sub new { my $class = shift; my $self = {}; return bless $self, $class; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl OOP
by jdporter (Paladin) on Oct 11, 2004 at 14:07 UTC | |
by hardburn (Abbot) on Oct 11, 2004 at 14:57 UTC | |
|
Re: Perl OOP
by BrowserUk (Patriarch) on Oct 11, 2004 at 14:13 UTC | |
|
Re: Perl OOP
by pelagic (Priest) on Oct 11, 2004 at 15:00 UTC | |
|
Re: Perl OOP
by gmpassos (Priest) on Oct 11, 2004 at 22:15 UTC | |
|
Re: Perl OOP
by SpanishInquisition (Pilgrim) on Oct 11, 2004 at 20:02 UTC | |
|
Re: Perl OOP
by newbio (Beadle) on Oct 12, 2004 at 06:09 UTC |