When to use an interface instead of an abstract class and vice versa?

Chirantan picture Chirantan · Jan 26, 2009 · Viewed 331.1k times · Source

This may be a generic OOP question. I wanted to do a generic comparison between an interface and an abstract class on the basis of their usage.

When would one want to use an interface and when would one want to use an abstract class?

Answer

Jorge Córdoba picture Jorge Córdoba · Jan 26, 2009

I wrote an article about that:

Abstract classes and interfaces

Summarizing:

When we talk about abstract classes we are defining characteristics of an object type; specifying what an object is.

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.