We don't bite newbies here... much | |
PerlMonks |
Re: construct a standard object oriented programby chhe (Sexton) |
on Mar 30, 2002 at 10:33 UTC ( [id://155419]=note: print w/replies, xml ) | Need Help?? |
Basically the perl features specific to object-orientation are not many. The rest is a application of a collection of conventions, style and idioms, which is why from my point of view the perl approach is so exciting. To define a class in perl from which objects can be created and against which functions can be called, you basically need a perl module with a constructor function, which can be named as you like - conventionally "new" -, you need to "bless" a datastructure of the module and return the "blessed" datastructure from the constructor. The returned "blessed" datastructure, can now be treated like a "object", in such that functions can be called upon it. The "methods" or functions of a blessed "Class" get the instance data of the object always a first parameter. The rest is as said very a matter of style and idioms, also inheritance, which is not specifically supported by perl, but with a more general approach, through the @ISA mechanism, where when a function is not found the "objects" package it looks up the @ISA variable for other packages to lookup. The fact that much of perls object-orientation is very much a matter of style and idioms is a powerful feature, because you are flexible in terms of design decisions: You make decisions very much depending in the context of your application needs. There are idioms for: different ways of representing an object, addressing privacy, automatically generating accessors methods, object destruction, functions being both class and instance methods, efficient ways of storing attribut data, debugging, loading objects at runtime, runtime dispatch of function calls etc. Also there are modules, which support some of these idioms ready to use, like ObjectTemplate and others.All this has been decribed, as my colleque commentors have already observed, in other places much better.
In Section
Seekers of Perl Wisdom
|
|