This question evently led me to question how much OOP I have written with Perl. Not much. As a matter of fact, whenever I did, it was not a serious endeavor.
Rather than question just how practical OOP is in Perl, I instead focus on abstract classes in Perl. Why do you need an abstract class in Perl?
First off. What is an abstract class?
don't answer that, it's a rhetorical question :)
An abstract class is class that is never meant to be instantiated, instead its existance is to provide a basis for other classes that will inherit from it. Java and C++ have reserved tokens for declaring abstract classes, but Perl does not. For that matter, Perl doesn't even have a 'class' reserved token (who needs it anyways). But that's okay, Perl is just following a path that has been accepted throughout the existance of modern day computers - if the 'hardware' can't do it, 'software' can and will be written to do it. Perl is just as capable of providing classes, abstract and concrete - it just might not be as 'pretty' as other languages.
Why are abstract classes even needed? What convience do they provide?
At first glance, the obvious answer is common functionality. For example, Java provides a toString() method that is defined in the Object class. Since all objects in Java are sub-classes of Object, they too have a toString() method. But Object is not an abstract class - you can create an Object class. Looks like common functionality is not the reason . . .
Rather than ask the question again - I will now jump straight to the point. When I said that an abstract class provides a common basis for other classes, I was not quite accurate, because a class does not have to be abstract to provide this basis. I should have instead said that an abstract class provides a common interface.
The textbook I was looking at was
Design Patterns
by qw(Gamma Helm
Johnson Vlissides), by the way. Here is their answer to why abstract
classes are a 'good thing' in a nut shell:
and I have to reprint their mantra - because it's a good one:
Now that is a bit extreme - but you will never have to worry about the 'type' of that value changing from a 'short' integer to a 'long' integer should scalability rear its ugly head.
But wait a second, Perl doesn't make the programmer worry about types - there are no 'floats' or 'double longs' - only scalars.
So, why does one need abstract classes in Perl? Also, are there any CPAN modules that use abstract classes?
UPDATE: Let me add to that last question:
"are there any CPAN modules that use abstract classes
internally?" I will continue to look myself.
Thanks,
Jeff
R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
L-L--L-L--L-L--L-L--L-L--L-L--L-L--
|
|---|