Wednesday, June 29, 2016

Abstract class VS Interface

abstract class vs interface c#

How to decide in which scenario Abstract class or Interface to be used?

-> When we are sure that design is not going to be changed then we should use interface. Otherwise we should use abstract class wherein we provide some functionality and anticipate multiple versions of your component

For e.g. When we know that there are going to be only 4 gears/Wheels to the care and not 5th one would be added then we choose to have an interface.
In case if there are changes to be done in interface then all the classes implementing it must be changed. Same is not with abstract class till the time we add non-abstract methods.

No comments:

Post a Comment