Chapter 2
Object Vocabulary
Object oriented (OO) programming has a language all its own. Fortunately for us, 
Perl provides a simple translation from the OO lexicon to everyday Perl.
12
 See 
Table 2 2 for a cheat sheet. Don't worry if this vocabulary isn't immediately clear, 
I'll provide more explanation as we go.
Table 2 2. OO Vocabulary Cheat Sheet
OO
Perl
Class
Package
Object
A reference blessed into a package
Method
A subroutine in a class
Object method
A method that expects to be called using an object
Class method
A method designed to be called using a class
Constructor
A class method that returns a new object
Using OO Modules
Before I show you the details of creating an OO module, it helps to know how to use 
one. Here's an example using IO::File, an OO wrapper around Perl's file operators 
(open, print, seek, and so on) included with Perl:
use IO::File;
# create a new IO::File object for writing "file.txt"
my $filehandle = IO::File >new(">file.txt");
# print to the file
$filehandle >print("This line goes into file.txt\n");
# close the file
$filehandle >close();
The three subroutine calls new(), print() and close() are examples of method 
calls. Method calls are the bread and butter of object oriented programming, and 
in typical Perl fashion, there's more than one way to do it. The preceding example 
12. Which is not the case for all those C programmers learning C++ they don't have a leg to 
stand on!
38






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

web hosting perl

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved