I don't claim to be any kind of expert when it comes to Object Oriented Programming, but I do understand the basics pretty well. Sometimes though, some of the more advanced things make me go "Whaaaaaaaaat???"
So my question today is this. What is the point of using abstract and interface classes? From what I can see, they don't actually add any functionality. Borrowing an example from the PHP manual, I can see how they could accomplish the exact same thing without extending the abstract class.
<?php
abstract class AbstractClass
{
// Force Extending class to define this method
abstract protected function getValue();
abstract protected function prefixValue($prefix);
// Common method
public function printOut() {
print $this->getValue() . "\n";
}
}
class ConcreteClass1 extends AbstractClass
{
protected function getValue() {
return "ConcreteClass1";
}
public function prefixValue($prefix) {
return "{$prefix}ConcreteClass1";
}
}
Why would I want to write that extra code if it doesn't actually add anything? The only reason I can see possibly using abstract or interface classes would be to have the abstract class in a separate file, fully commented with docBlocks, which would leave me free to implement the main class without using up all that extra space that would normally be taken up by said comments. I suppose doing this would also make it easier for people reading my code to figure out what's going on in the program. Especially if it's a fairly large application.
I've been doing some research on the subject lately, and have yet to come up with a tutorial or any other article that explains the usefulness of abstract/interface classes. They all show 'how' to use them, but that's it. Am I missing something here?