Tuesday, 27 June 2017

When to use interface and abstract class?

An abstract class can have shared state or functionality.

An interface is only a promise to provide the state or functionality.

A good abstract class will reduce the amount of code that has to be rewritten because its functionality or state can be shared. The interface has no defined information to be shared.

In case of abstract classes we are defining characteristics of an object type, specifying what an object is but in the case of an interface we define a capability and we bond to provide that capability, we are talking about establishing a contract about what the object can do.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...