I have seen many answers on stackoverflow, but I didn’t find an answer that is matching mine.
Apart from all those difference, Does it make sense if we say an abstract class abstracts the implementation of behaviour while an interface abstracts the type which implements the behaviour.
I have seen many answers on stackoverflow, but I didn’t find an answer that
Share
The main differences from design point of view are that:
So I would say you are correct in the statement that “an abstract class abstracts the implementation of behaviour while an interface abstracts the type which implements the behaviour”
Abstract class: provides requirement to implement some methods (you override methods of the abstract class)
Interface: defines only a contract. Indicates that a class that implements the interface has methods of the interface (you implement an interface)
For example:
by implementing an interface on an existing class, you just declare adding the interface methods to the contract of the class. The class may already implement all the methods of the interface and you do not need to change anything in the existing class.
by changing the base type to an abstract class, you are required to override all the methods, even if methods with the same names as abstract methods of the base class already exist on the type.