Siaris
Simple Things
Syndicate: full/short
Siaris
Categories
General0
News2
Programming2
LanguageBits0
Perl50
Ruby10
VersionControl1
Misc0
Article Calendar
<= April, 2014
S M T W T F S
12345
6789101112
13141516171819
20212223242526
27282930
Search this blog

Key links
External Blogs
Brought to you by ...
Ruby
1and1.com

Additional OO Concepts and Further Reading

Andrew L. Johnson (First published by ItWorld.com 2001-07-12)

In the past few articles we have only touched the surface of OO programming in Perl by building a relatively simple class. This series has not been 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, out 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 the 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).

There is a great deal of further information that 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

As well, Damian Conway has written and excellent book on the subject of OO programming with Perl:

    Object Oriented Perl. By Damian Conway (Manning Publications)

This book is widely recognized by many in the Perl community to be 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.

*****