Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Inheritance and NEXT

by pjf (Curate)
on Jun 25, 2002 at 00:20 UTC ( #176994=note: print w/replies, xml ) Need Help??


in reply to inheritance: constructors

Splitting construction from initialisation is a very common, clean, and recommended way of proceeding. It's already been covered, so I won't repeat it here. It's a good idea to do this even if you're not doing inheritance at the point -- things often change, and one of the advantages of OOP is that objects are supposed to be inheritable.

For a clean and easy way to call parent initialisers "when appropriate", you might consider the use of NEXT. NEXT will call your parent's constructor if it exists and if it's appropriate. It will handle multiple inheritance without difficulty. It's also going to be a standard module in Perl 5.8.0.

use NEXT; # ... sub _init { my $self = shift; $self->NEXT::UNSEEN::_init(@_); # My init goes here... }
You can find a whole chapter on NEXT and why it's useful in the Object Oriented Perl training notes from Perl Training Australia. TheDamian has also written an article on use.perl which can be found here.

Cheers,
Paul Fenwick
Perl Training Australia

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://176994]
help
Chatterbox?
[chickenman]: Thank you, I am looking for enlightenment! ;)
[chickenman]: Unfortunatly no standard, Its the Output of some command
[Discipulus]: ouch! it outputs always same fields?
[harishnv]: Can someone give me a solution fast

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2018-02-20 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (268 votes). Check out past polls.

    Notices?