in reply to OOP and derived classes
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: OOP and derived classes
by Anonymous Monk on Feb 14, 2015 at 20:04 UTC | |
by Anonymous Monk on Feb 14, 2015 at 20:17 UTC | |
by Anonymous Monk on Feb 14, 2015 at 21:04 UTC | |
by LanX (Saint) on Feb 14, 2015 at 22:28 UTC | |
by Arunbear (Prior) on Feb 15, 2015 at 13:41 UTC | |
by choroba (Cardinal) on Feb 14, 2015 at 21:38 UTC | |
by Anonymous Monk on Feb 14, 2015 at 22:21 UTC |