What is the difference between a Class Abstraction and an Object Interfaces in PHP? I ask because, I don’t really see the point to both of them, they both do the same thing! So, what are the advantages of disadvantages using both against one or the other?
Class Abstraction:
abstract class aClass
{
// Force extending class to define these methods
abstract public function setVariable($name, $var);
abstract public function getHtml($template);
}
Object Interface:
interface iClass
{
// Force impementing class to define these methods
public function setVariable($name, $var);
public function getHtml($template);
}
You can implement multiple interfaces but only extend one class.
Possible:
Not Possible:
Additionally, an interface cannot have implementation.
Possible:
Not Possible:
From the Java Glossary:
You should also take a peek at this question – Damien’s point about how an interface is a contract is an important one.