Interfaces and abstract classes in object oriented programming [duplicate]
Possible Duplicate:
Interface vs Abstract Class (general OO)
Hi guys,
I decided to dig deep into OOP and have been taking on Design patterns practicing with PHP. I just had a question I would like views on. Interfaces and Abstract classes, which has more advantages? It might be vague but any light shed would be helpful. I can write code to use both and understand each one by concept but I am just wondering which should I be use by default, and why should I be using one over the other. Basically use-case scenarios.
Thanks in advance.
Eagletrophy
I use both. To me, interfaces are to describe functionality, and abstract classes are to provide base functionality.
What I mean, is whenever I require an "object type" as a parameter to a method/function, I almost always declare an interface for that purpose. So my methods have signatures like foo(BarInterface $bar)
Whenever I make multiple children from a class (and can share functionality), I make an abstract class that provides the base implementation (and also extends the interface)...
I hope that helps...
精彩评论