0

I have researched Abstract classes and interfaces in PHP and found some best practice examples, but I'm still a little confused and failed several times in interviews due to this. So, from my experience I think the following is true:

Interface

Interface will have to be implemented in classes. For example:

interface BikeDrive{
    public function MotorCycleDriving($FootGear, $RightHandBrake)
}

Abstract class is a core functionality, for example every vehicle:

Abstract Class Drive(){

}

Please guide me through the concept.

Oldskool
  • 34,211
  • 7
  • 53
  • 66
ayaz khan
  • 141
  • 8
  • Have a look at dependency injection and Polymorphism – Liam Sorsby Jun 30 '15 at 08:02
  • Take a look at [this](http://stackoverflow.com/questions/1814821/interface-or-an-abstract-class-which-one-to-use) – Naruto Jun 30 '15 at 08:02
  • @LiamSorsby Yes I have read about Polymorphism, it is easy (Same function with different behavior) but want to know about **Interface** and **Abstract** – ayaz khan Jun 30 '15 at 08:05
  • @Naruto yes i have viewed it is good example but want to more clear – ayaz khan Jun 30 '15 at 08:06
  • @ayazkhan interfaces and abstract classes are used in Dependancy Injection and polymolphism. If you want to learn about abstract classes and interfaces only then you maybe better refering to php.net. Your abstract class "drive" doesn't actually do anything unless you are wanting to implement the interface into it. What is it that you aren't clear about the abstract/interface especially if you understood Polymorphism? – Liam Sorsby Jun 30 '15 at 08:11
  • See: http://stackoverflow.com/questions/479142/when-to-use-an-interface-instead-of-an-abstract-class-and-vice-versa?rq=1 – Bv202 Jun 30 '15 at 08:21
  • @LiamSorsby Yes i have understood Polymorphism, but i think interface and abstract are different topic. I know about php.net, but at there abstract and interface described in very difficult words and examples which i didn't understand, so i want to clear it with easy examples – ayaz khan Jun 30 '15 at 08:22

0 Answers0