Difference between Abstract Class and Interface In PHP


Abstract Classes

  • An abstract class can provide some functionality and leave the rest for derived class.
  • The derived class may or may not override the concrete functions defined in 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.
About these ads

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s