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

Re^2: kind of effort required for learning OO perl ?!

by chromatic (Archbishop)
on Jul 29, 2010 at 19:25 UTC ( [id://851994]=note: print w/replies, xml ) Need Help??


in reply to Re: kind of effort required for learning OO perl ?!
in thread kind of effort required for learning OO perl ?!

I can't recommend some of this advice; it looks prone to making messes.

package dog;

Lowercase module names are, by convention, pragmas.

    return(bless(dog->new(),$class));

Why double bless? If the parent constructor is at all sane, it allows subclassing.

my $doggie = new cockerSpaniel();

The indirect method invocation syntax is fraught with peril; it's ambiguous to parse and Perl occasionally guesses incorrectly depending on the compilation order of your code.

Also inheritance is not an essential part of object orientation. Arguably neither is encapsulation.

You're absolutely right about object design being important. Most tutorials never teach that, and it's vital to writing effective OO.

Replies are listed 'Best First'.
Re^3: kind of effort required for learning OO perl ?!
by InfiniteSilence (Curate) on Jul 29, 2010 at 21:56 UTC
    What double bless...are you referring to this:
    sub new { my ($class) = @_; return(bless(dog->new(),$class)); }
    ?

    I borrowed this syntax from the perlbot example:

    sub new { my $type = shift; my $self = Bar->new; $self->{'biz'} = 11; bless $self, $type; }
    When I checked that $self reference was indeed blessed before it was passed through bless again:
    DB<3> p UNIVERSAL::isa($self,'Bar'); 1
    What is the harm?

    Celebrate Intellectual Diversity

      What does dog->new() return? If you didn't have any new() defined in Bar, what would Bar->new() return?

      I borrowed this syntax from the perlbot example

      Thanks. I'll submit a patch to fix that example code.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://851994]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-16 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found