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

前端 未结 23 2144
忘了有多久
忘了有多久 2020-11-22 04:29

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 wou

23条回答
  •  长情又很酷
    2020-11-22 05:04

    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.

提交回复
热议问题