Powered by Blogger.

Difference Between Abstract Class and Interface in PHP


DIFFERENCE BETWEEN ABSTRACT CLASS AND INTERFACE IN PHP

Abstract Classes:


  • An abstract class can provide some functionality and leave the rest for the derived class.
  • The derived class may or may not override the concrete functions defined in the base class.
  • The child class extended from an abstract class should logically be related.


Interface:


  • An interface cannot contain any functionality. It only contains definitions of the methods.
  • We can have a class extend from more than one Interface.
  • The derived class must provide code for all the methods defined in the interface.
  • Completely different and non-related classes can be logically grouped together using an interface.

No comments