In the past few articles, I have only touched the surface of OO
programming in Perl by building a relatively simple class. This series
was not intended to teach OO programming per se, but rather to
introduce the topic with a working example and provide a starting point
for those wishing to delve further.
In particular, of the following general OO concepts, Abstraction,
Encapsulation, Inheritance, and Polymorphism, we have only really
addressed encapsulation hiding the internal workings and data inside
the object and providing an external interface to the programmer.
Abstraction is just generalization. Our slot class was not very
abstract because we hard coded in the wheels and payoff table. A more
abstract slot machine class might be defined so that a variety of slot
machines and payoff tables could be used.
Inheritance and Polymorphism define relationships among classes one
class might be very general and not really intended to be used
directly. Other classes can then be defined as derived or child classes
of this class and they can inherit all of the properties and methods of
their parent class. Often when inheriting from a parent class, the new
class needs to change or override one or more methods. This is referred
to as polymorphism (child classes need not be identical to their
parents, nor to their siblings).
A great deal of further information can be found in the standard Perl
documentation:
perldoc perltoot # an OO primer
perldoc perlboot # another OO primer
perldoc perltootc # a tutorial on class data
perldoc perlobj # the manpage for Perl objects
perldoc perlbot # OO tips and tricks
Damian Conway has written an excellent book as well on the subject of
OO programming with Perl:
Object Oriented Perl
By Damian Conway (Manning Publications)
http://www.manning.com/Conway/index.html
This book is widely recognized by many in the Perl community as the
bible of OO programming in Perl. It is very readable, highly
informative, and even funny. I definitely recommend it for anyone who
wants to learn how to do OO programming in Perl.
Next Week: What is Perl-6?