When to use interfaces and when to use abstract classes?
In current article we will discuss, When to use interfaces, and when to use abstract classes? Most of the time developers are confused on design time weather to use interface or abstract class.
when to use abstract classes?
When we talk about abstract classes we are defining characteristics of an object type specifying what an object is.
When to use interface?
When we talk about an interface and define capabilities that we promise to provide, we are talking about establishing a contract about what the object can do.
Here I am listing the differences between Interface and abstract class
I hope this article will understand you to When to use interfaces, and when to use abstract classes.
when to use abstract classes?
When we talk about abstract classes we are defining characteristics of an object type specifying what an object is.
When to use interface?
When we talk about an interface and define capabilities that we promise to provide, we are talking about establishing a contract about what the object can do.
Here I am listing the differences between Interface and abstract class
Feature
|
Interface
|
Abstract
|
Multiple inheritance
|
||
Implementation
|
||
Access Modifiers
|
||
Core VS Peripheral
|
An abstract class defines the core identity of a class and there it is used for objects of the same type.
|
|
Homogeneity
|
If various implementations only share method signatures then it is better to use Interfaces.
|
If various implementations are of the same kind and use common behaviour or status then abstract class is better to use.
|
Speed
|
||
Adding functionality (Versioning)
|
||
Fields and Constants
|
I hope this article will understand you to When to use interfaces, and when to use abstract classes.
awesome post, very helping!
ReplyDelete