Perl/Tk saves your favourite tools

Main
back: References in Perl
next: OO in Perl -2

Just to fresh-up some things about OO in Perl. In practice, the syntax is simple. But writing OO-programs requires different programming techniques than functional programming.

In Perl, objects are simply references to hashes (in rare cases you could use references to arrays or references to scalars too). The hash stores the data of the actual object. The reference is blessed into a class, which is in Perl represented by a single package.

Example:

   $teacher = {name => 'Mark', awake => 1};
   bless $teacher, 'Animal::Human::Male';
Now we have one object (referred to by $teacher), which is of class Animal::Human::Male. The call
   $teacher->eat('now');
will be translated by Perl to
   Animal::Human::Male::eat($teacher, 'now').

The creation of the object (the creation of a blessed reference to a hash with data, also called instantiation is per agreement performed a function called new.

Books

There are a few books on writing Perl in the OO way: read one.
???????????????????????????????
By Damian Conway
 
Advanced Perl Programming Chapter 7.
By Sriram Srinivasan, 1st Edition August 1997, O'Reilly,
ISBN: 1-56592-220-4, 434 pages, US$34.95.

 
References in Perl OO in Perl -2

Created by Mark Overmeer with PPresenter on 11 juli 2001.