Can you help me understand in a practical example the usage abstract classes vs interfaces?

前端 未结 9 606
孤城傲影
孤城傲影 2020-12-24 04:09

Can you give me an almost overly simplistic understanding of abstract class vs inheritance use and help me so I can truly understand the concept and how to implement? I have

9条回答
  •  醉梦人生
    2020-12-24 04:38

    1. An interface is a contract. This is the place where you want to describe the functionalities you'll provide, without any implementation details

    2. An abstract class is a class whose purpose is to share implementation details between its sub-classes. Since it's here only for code sharing/factorisation purposes, it cannot be instantiated

    3. your actual class will inherit from your abstract class, and implement its class-specific functionalities while using the code shared in the abstract class if needed.

提交回复
热议问题