Hi Tony.
Perl provides very minimal extra magic for object oriented programming. In fact, as I understand it, there's only 3 things Perl does for you to implement OOP:
That's basically it. No automatic constructor calls, no automatic object allocation. Your ``object'' is actually (usually) just an anonymous hash which you create in (and is returned by) your `new' class method, and that gets passed around for you when calling methods. The ``instance attributes'' are just keys in that hash, and ``class attributes'' are just lexicals in the module where you write your methods.
When using objects, as long as you only ever access attributes via methods (and not directly -- which you, of course, can if you like to live dangerously), everything mostly just works like it ought to.
One last tip: The method that gets called is always looked up via the object reference (that blessed anonymous hash), so even if some base class method calls another base class method, if your own child class has a method of that name, the child class method is the one that'll get used.
Addendum: If a method is expecting certain instance attributes to exist, you'be better make sure they're there. Methods and instance attributes (the values you have in your anonymous hash) are two totally different things. Welcome to Perl OO: Watch your step. Here's your helmet. :)
In reply to Re: oops concept in perl programming
by j3
in thread oops concept in perl programming
by Tony1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |