On Dec 7, 2005, at 4:36, Ken Farmer wrote:
I have tried this question in a couple of other places but the
answers are far above my current level of understanding of oop -
which is the level of very interested newbie - real newbie. So
here goes again.
I make an empty (of data) perl object1 with an included method
which can be called to put data into the hash inside this object. I
can now call that method and insert data. Simple OOP - it works.
Now I make another empty object2 and inherit object1. I can call
the inherited method from object1 through object2 and it also
works, but not like I assumed it would.
The suspicious point, and one that is base of the next reasoning so I
am goint to make it explicit, is that objects do not inherit from
objects. Classes do.
In that sense, and roughly speaking, data is not inheritable, because
data belong to objects. "State inheritance" is done by hand.
Now, if object1 belongs to class1, and object2 belong to class2, and
class2 is child of class1 you, implement "data inheritance" in the
constructor of class2 calling SUPER:
package class2;
use base 'class1';
sub new {
my ($class, $data1, $data2) = @_;
my $self = bless {}, $class;
$self->SUPER::new($data1);
$self->{data2} = $data2;
return $self;
}
In that code $data1 is supposed to be some state of "level" class1,
so that methods in class1 assume it exists, class1::new may create
auxiliar data from $data1 (in keys different from data2), etc. On the
contrary, $data2 is supposed to be data of class2 "level, methods of
class2 use it, but methods of class1 don't.
I don't know whether that can put order on the concepts, please feel
free to ask as much as needed.
-- fxn
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>