Abstract V Interface
Abstract V Interface
Interface A class may inherit several interfaces. An interface cannot provide any code, just the signature.
Abstract class A class may inherit only one abstract class. An abstract class can provide complete, default code and/or just the details that have to be overridden. An abstract class can contain access modifiers for the subs, functions, properties An abstract class defines the core identity of aclass and there it is used for objects of the same type.
Access Modfiers
An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public Interfaces are used to define the peripheral abilities of a class. In other words both Human and Vehicle can inherit from a IMovableinterface. If various implementations only share method signatures then it is better to use Interfaces.
Core VS Peripheral
Homogeneity
If various implementations are of the same kind and use common behaviour or status then abstractclass is better to use. Fast
Speed
Requires more time to find the actual method in the corresponding classes. If we add a new method to an Interface then we have to track down all the implementations of theinterface and define implementation for the new method. No fields can be defined ininterfaces
If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly. An abstract class can have fields and constrants defined