Perl/Tk saves your favourite tools | |||
Main back: References next: OO -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.
BooksThere are a few books on writing Perl in the OO way: read one.
| ||
Created by Mark Overmeer with PPresenter on 5 august 2001. |