Tuesday 17 January 2012

OOPerl Terminology

In the object-oriented world, many words describe only a few concepts. If you've programmed in another object-oriented language, you might like to know how familiar terms and concepts map onto Perl.
For example, it's common to call objects instances of a class and those objects' methods instance methods . Data fields peculiar to each object are often called instance data or object attributes , and data fields common to all members of that class are class data , class attributes , or static data members .
Also, base class , generic class , and superclass all describe the same notion (a parent or similar ancestor in the inheritance hierarchy), whereas derived class , specific class , and subclass describe the opposite relationship (a child or descendent in the inheritance hierarchy).
C++ programmers have static methods , virtual methods , and instance methods , but Perl only has class methods and object methods . Actually, Perl only has methods. Whether a method acts as a class or object method is determined solely by actual usage. You could call a class method (one expecting a string argument) on an object (one expecting a reference), or vice versa, but you shouldn't expect reasonable results if you do.
A C++ programmer thinks about global (class) constructors and destructors. These correspond to module initialization code and per-module END{} blocks respectively.
From the C++ perspective, all methods in Perl are virtual. This is why their arguments are never checked for function prototypes as regular built-in and user-defined functions can be. Prototypes are checked by the compiler at compile time. You can't determine until run time the function that a method has called
In the object-oriented world, many words describe only a few concepts. If you've programmed in another object-oriented language, you might like to know how familiar terms and concepts map onto Perl.
For example, it's common to call objects instances of a class and those objects' methods instance methods . Data fields peculiar to each object are often called instance data or object attributes , and data fields common to all members of that class are class data , class attributes , or static data members .
Also, base class , generic class , and superclass all describe the same notion (a parent or similar ancestor in the inheritance hierarchy), whereas derived class , specific class , and subclass describe the opposite relationship (a child or descendent in the inheritance hierarchy).
C++ programmers have static methods , virtual methods , and instance methods , but Perl only has class methods and object methods . Actually, Perl only has methods. Whether a method acts as a class or object method is determined solely by actual usage. You could call a class method (one expecting a string argument) on an object (one expecting a reference), or vice versa, but you shouldn't expect reasonable results if you do.
A C++ programmer thinks about global (class) constructors and destructors. These correspond to module initialization code and per-module END{} blocks respectively.
From the C++ perspective, all methods in Perl are virtual. This is why their arguments are never checked for function prototypes as regular built-in and user-defined functions can be. Prototypes are checked by the compiler at compile time. You can't determine until run time the function that a method has called

No comments:

Post a Comment

Tweets by @sriramperumalla