Hello all Monks
I've been banging my head for a few hours now and I really need some input from others..
For this example, say I have 3 classes.
CLASS_A
CLASS_B
CLASS_C
I want the inheritance to look like this.
CLASS_C ISA CLASS_B ISA CLASS_A
So that if I want to access a method in CLASS_A I want to be able to do.
my $instanceC = CLASS_C->new(); $instanceC->method_from_class_A();
So,, this is where i'm stuck..
I start from the bottom...
Code for CLASS_C
package CLASS_C; use CLASS_B; @ISA = ('CLASS_B'); use strict; sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; $self->{attribut} = 1; $self = $class->SUPER::new(self => $self); return $self; } 1;
Code for CLASS_B
package CLASS_B; use CLASS_A; @ISA = ('CLASS_A'); use strict; sub new { my $proto = shift; my (%params) = @_; my $class = ref($proto) || $proto; my $self = $class->SUPER::new(); foreach my $attr (keys %{$params{'self'}}) { $self->{$attr} = $params{'self'}->{$attr}; } return $self; } 1;
Code for CLASS_A
package CLASS_A; use strict; sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = {}; bless($self,$class); return $self; } 1;
What I know:
Everything fails into a endless loop because of the call to SUPER::new inside CLASS_B definition calls itself... But how should I write it?
Regards
Joakim
UPDATE: I had a call inside CLASS_B::new which called a 'CLASS_C::new' which in turn called CLASS_B::new again .. forever..
Apperently I were to tired yesterday when trying this..
But I guess it's not a waste, hopefully this post will help someone in the future =)
In reply to Inheritance - parent of parent (solved) by jockel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |