-1

I know the concepts of Abstract Class and Interface Class. But I want real time example which explains both the concept in our design. Can anyone help with this?

user3167857
  • 55
  • 1
  • 10

2 Answers2

0

Here I am mentioning some point what we can do with abstract class and interface

  1. In abstract class you can define abstract methods which should be public or protected. but in Interface you can define public abstract method only.
  2. In abstract class you can define data members and constants but in interface you can define constants only.
  3. In abstract class you can define body of method and you can inherit in sub class, but in interface you can not define body of method.
  4. you can implement multiple interface in a sub class, but you can not inherit multiple abstract classes in a sub class.

Example

In Major Frameworks, uses interfaces for different types of data source class. If we want to make data source class for new introduced database then we must have to implement their interface in our class so it make well maintained code and methods parameters.

Haresh Vidja
  • 8,340
  • 3
  • 25
  • 42
  • 2
    An abstract class cannot declare abstract private methods.. only public and protected.. However, an abstract class can contain private methods which could be called only inside the class itself – Mihai Matei Aug 03 '16 at 06:35
0

Both have little different scenerios... Abstract classes also contains method definition as you know interface does not. But if you defines abstract class you can not inherit more than one classes from child class. But In case of interface you can do that and implement the methods declared inside the interface.

These scenerios are used in the software development as we just declared the signature of the method and then user can write his.her own code inside the method by overriding it.

PHP Geek
  • 3,949
  • 1
  • 16
  • 32