Free tutorial on Object Perl (Object-Oriented Perl)

T

tim

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.
 
P

Paul Lalli

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

.... is a HTTP 500

Paul Lalli
 
B

Brian McCauley

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top