Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


The Perl You Need to Know Part 24: Introduction to Object Oriented Perl - Page 169

May 21, 2001

As in watercolors, programming is a matter of perspective — there are several ways to view the same scene, and anyone else's way is clearly wrong. That's where object oriented programming, or OOP, comes in, an increasingly popular "other way" to approach working with data in programs. While important languages such as C++ and Java are founded on OOP principles, Perl is typically accomodating, supporting either traditional or OOP perspectives. Although use of object orientation in Perl is technically optional, in practice you are likely to at least rub shoulders with the object model when using external modules. In fact, we've already seen object syntax in this series when working with the ever popular CGI and DBI modules. This month, we'll take stock of that syntax, and begin a broader understanding of what working with objects in Perl is really all about.

Objects of Our Affection

While working with object oriented programming is portrayed as somehow novel, leading edge, or requiring deep study, we actually use object orientation in our lives daily. Every appliance in your kitchen, for instance, flaunts the principles of OOP. Consider the stove: it probably has four knobs, one for each burner. The stove's interface requires that you turn a knob to make a burner more or less hot. You are not directly concerned with how the stove makes the burner hot (maybe it uses a spark and gas fuel, maybe it uses an electric element, and so on) — the interface merely requires you to turn the knob. Extend the same analogy to your microwave oven and the same principles apply, although the interface is more complex and supports operations more highly abstracted than directly controlling degree of heat. In other words, the microwave, like the stove, still ultimately heats food via a process of no concern to you, but the microwave determines heat level indirectly by way of higher order parameters — power level, time, or even type of food (potato, popcorn, etc.).

The typical metaphor for a program object is the "black box", a hypothetical device that you control with buttons or levers, and it does its thing internally. The crucial aspect of the black box (stove, microwave, etc.) and therefore of an object in OOP is that its external interface is decoupled from its internal function. This has two important consequences:

  • Anyone can leverage the power of the object simply by learning its interface, without needing to understand how the object achieves its goals. The power of this model can be seen all around us, from vacuum cleaners to stoves to the cars we drive, and even the computers we use.

  • Designers and engineers can modify, incrementally or radically, the internal function of the object while minimzing change to its external interface. If you can drive to the market in a Dodge Neon you could probably also do so in a Porsche Boxter or an electric hybrid Honda Insight, because they share fundamentally similar interfaces, while functioning quite differently internally.

Therein lies the programmer's affection for objects, especially as building blocks. Indeed, we'll soon see just how closely objects in Perl are related to the traditional Perl building blocks of modules and packages.

Contents:

Classism
A Matter of (Indirect) Syntax

A Private Stash (of modules) - Page 168
The Perl You Need to Know
Classism - Page 170


Up to => Home / Authoring / Languages / Perl / PerlfortheWeb




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers