-3

What is difference between Abstract method in abstract class and Interface method in interface PHP ? Note: I am not asking difference between Abstract class and Interface. I am asking only methods.

  • 1
    Possible duplicate of [Interface vs Abstract Class (general OO)](https://stackoverflow.com/questions/761194/interface-vs-abstract-class-general-oo) – catcon Aug 07 '19 at 06:05
  • Possible duplicate of [What is the difference between an interface and abstract class?](https://stackoverflow.com/questions/1913098/what-is-the-difference-between-an-interface-and-abstract-class) – Sayed Mohd Ali Aug 07 '19 at 06:16
  • @tunay novruz the differences are same, you cannot change OOPS concept... – Sayed Mohd Ali Aug 07 '19 at 06:17
  • As far as I know, there is no difference (except for abstract method can be protected while interface method must be public), both can't have a body and needed to be implemented by the class extended/implement the abstract/interface. The main difference is laid on the class itself, not the method. An abstract class can be half defined (has methods with and without body), while an interface is full abstract (only have abstract method) – catcon Aug 07 '19 at 06:37

1 Answers1

1

The following is my understanding of why they exist and how they can be useful. The are the same in general. They exist to give flexibility for better OOP design in my mind.

  • Interface methods must be implemented by any class implementing the Interface.
  • The same way abstract methods must be implemented by any class that extends the abstract class.
  • A class can implement multiple Interfaces but can only extend one class (abstract or concrete).
  • It is possible to have multiple implementation of an Interface with different behaviors.
  • It is also possible to implement an Interface in abstract. That is, providing boiler plate for implementation of an Interface with most common methods implemented (at least with default behavior) and leave the implementation of the rest of the Interface methods to concrete class. This abstract implementation though can force the concrete class to implement some abstract methods (on top of Interface methods). These abstract methods may not necessarily be required for other implementations of the same Interface and should not be enforced by the Interface so they should not be in the Interface.
Navid
  • 894
  • 7
  • 14