Free tutorial on Object Perl (Object-Oriented Perl)

Discussion in 'Perl Misc' started by tim@timothyhowe.com, Dec 22, 2005.

  1. Guest

    In the many years since Object Perl first appeared, I never found an
    introduction or tutorial that I liked. So I wrote my own.

    The tutorial is at

    http://www.timothyhowe.com/software

    (click on Object Perl).

    The Object Perl Tutorial, Part 1 presents a very compact explanation of
    object programming using Perl, illustrated with a complete working
    example program, without subclasses.

    Part 2 builds on Part 1 by adding subclasses to demonstrate
    inheritance. It also demonstrates the use of objects to model a
    many-to-many relationship.
    , Dec 22, 2005
    #1
    1. Advertising

  2. Paul Lalli Guest

    wrote:
    > In the many years since Object Perl first appeared, I never found an
    > introduction or tutorial that I liked. So I wrote my own.
    >
    > The tutorial is at
    >
    > http://www.timothyhowe.com/software
    >
    > (click on Object Perl).
    >
    > The Object Perl Tutorial, Part 1 presents a very compact explanation of
    > object programming using Perl, illustrated with a complete working
    > example program, without subclasses.


    I fail to see how this could be considered any better than
    perldoc perltoot
    perldoc perlobj
    or the Alpaca

    > Part 2


    .... is a HTTP 500

    Paul Lalli
    Paul Lalli, Dec 22, 2005
    #2
    1. Advertising

  3. wrote:
    > In the many years since Object Perl first appeared, I never found an
    > introduction or tutorial that I liked. So I wrote my own.
    >
    > The tutorial is at
    >
    > http://www.timothyhowe.com/software
    >
    > (click on Object Perl).
    >
    > The Object Perl Tutorial, Part 1 presents a very compact explanation of
    > object programming using Perl, illustrated with a complete working
    > example program, without subclasses.


    In Perl TMTOWTDI.

    However there are a number conventions that your tutorial ignores:

    Object constructors are conventionally called 'new' (not 'create')
    unless there's a reason to call them something else.

    Within an instance method the current object is conventionally called
    $self (not $this).

    Method calls should conventionally use the -> syntax rather than
    indirect objects except in a few special cases.

    Programs using objects should not fiddle with their internals.
    Certainly you should think of the value of the Dog consttuctor as
    being of type 'Dog' and not put it in a variable that has 'HR' (as an
    abreviation of 'hash reference') in the name.

    ($thisRH->{name}, $thisRH->{weight}, $thisRH->{voice}) would more
    conventionally be written as a slice.

    Your example says

    $carlRH = create Dog ('Carl', 14, 'Yap');

    It is exceptionally rare in real (well written) code to want to store
    the return value of a constructor into an existing scalar variable. As
    such it would be more realistic for you example to say:

    my $carl = Dog->new('Carl', 14, 'Yap');


    Oh, and bless() modifes the _referent_ not the _reference_.

    my $thing = {};
    my $another_reference = $thing;
    print ref $another_reference; # Prints HASH
    bless $thing, 'Some::Class'; # Modifies %$thing
    print ref $another_reference; # Prints Some::Class
    Brian McCauley, Dec 22, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nus

    object-oriented perl

    nus, Dec 24, 2003, in forum: Perl
    Replies:
    0
    Views:
    517
  2. Replies:
    2
    Views:
    426
    Bruno Desthuilliers
    May 26, 2008
  3. george
    Replies:
    0
    Views:
    1,118
    george
    Aug 29, 2008
  4. mohammed_a_o
    Replies:
    0
    Views:
    275
    mohammed_a_o
    Nov 30, 2010
  5. rolo
    Replies:
    3
    Views:
    172
    Robert Klemme
    Apr 9, 2004
Loading...

Share This Page