In Perl when you create a new derived class should you explicitly create a base instance inside the derived class constructor?Here's a simple answer: yes, you should. You don't get 'base instance' automatically.
Longer version: I don't know Java, but I suppose Java's object is (a pointer to) a struct-like thing, and a derived class appends its part (instance variables or whatever Java calls them) to the 'base part'. OTOH, Perl's object is (a reference to) anything at all. For example, a string, a number, array, hash, function... There is no 'base instance' and 'derived instance', just 'instance'. Here's a function object:
$ perl -E 'sub method { my $self = shift; $self->() } my $obj = sub { say "HELLO" }; bless $obj; $obj->method()' HELLO
In reply to Re: OOP and derived classes
by Anonymous Monk
in thread OOP and derived classes
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |