[Israel.pm] Objects and classes
lists at woobling.org
Sun Jan 11 13:57:09 PST 2004
On Sun, Jan 11, 2004 at 11:05:46PM +0200, semuel wrote:
edited for brevity
> Apache::RequestRec basically holds the request and the response ...
> few methods.
> Apache::RequestIO, that expand that functionality. it add methods
Apache::RecquestIO extend's Apache::RequestRec's behavior, if you're
looking for the term.
> The question is: have you seen other cases of classes that do something
You mean really in general? Look at the IO namespace on CPAN. Pretty
much everything inherits from IO::Handle.
Pod::Parser is a base class for a pod munger - it isn't that useful on
it's own, and that's what makes it even more useful. Pod::Stripper is
based on that. Humbly i'll admit to Pod::Wrap aswell.
In Perl, the package variable @ISA defines the inheritence list for a
perldoc perlvar -> @ISA has some insight.
> It's like plating a method inside other object. Is this style is popular?
Subclassing is it's name, and not as it should be, in the opinions of many.
... Some theory:
The concept of inheritence is to organize your definitions logically.
Say you wrote a class: Dog. It can bark, and eat.
And then you have a class called Retreiver, which has fetch, and swim.
The Retreiver class can extend Dog, because retreivers can bark, and
eat. Some dogs are too stupid to fetch though.
The Boxer class will also extend Dog, but it's swim method will not be
the same as Retreiver - instead it will run back to the car.
You could then subclass Retreiver further, with Labradore and Golden,
but their functi- personality is pretty similar - it's just the data
If you insist, Dog::Retreiver::Golden can inherit functionality from
Dog::Retreiver::Labradore, and Dog::Spaniel::Water.
In essence what you get is a tree of classes.
This is called an is-a relationship, because a Retreiver is-a Dog.
I've heard lots of good about Damien Conway's OO book
(http://www.manning.com/Conway/). I've even purchased the PDF version
- but i've yet to read further than the introduction.
Best of luck!
() Yuval Kogman <nothingmuch at woobling.org> 0xEBD27418 perl hacker &
/\ kung foo master: /me groks YAML like the grasshopper: neeyah!!!!!!
More information about the Perl