Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Inheritance and NEXT by pjf
in thread inheritance: constructors by Basilides

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-19 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found