Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi 2teez,

I'm not really happy with your suggestion for a newcomer. Why?

1) Choroba presented a simple constructor (as strong as pure water to stay with your metaphor) where you can can overwrite the default values of name and tail independently in a way most people would expect working with constructors in Perl. The positional parameters to new you present is not very common IMHO. So, I think Corion's constructor is really simple enough.

2) In package main you then do a

print $cat->{'name'}, $/;

which means you circumvent encapsulation (yes, I know, for debugging purposes). You show that to a newcommer to whom should be taught the "right" thing.

3) The point above IMHO comes only from the fact that you define the method nameMe in the child class. Why haven't you defined it in the base class? Then you wouldn't have to break encapsulation in your example and you would have shown inheritance in a nice mini example.

Be sure, I wouldn't have written this comment when Amblikai wouldn't have been so "excited" about your example. Please consider my comment as a hopefully constructive criticism.

And yes, Tobyink's answer is a hard drink to newcomers, but worth studying.

Best regards
McA


In reply to Re^2: Point me in the right direction with OO inheritance and static variables by McA
in thread Point me in the right direction with OO inheritance and static variables by Amblikai

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 having a coffee break in the Monastery: (6)
As of 2024-04-25 08:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found