The purpose of interfaces continued

后端 未结 13 1400
轮回少年
轮回少年 2020-12-03 02:28

OK so I gather that Interfaces are a way to enforce that an object implements a certain amount of functionality, without having to use inheritance. Kind of like a contract.

13条回答
  •  执笔经年
    2020-12-03 02:42

    You are confusing interfaces and inheritance. They are different concepts and can complement to each other. If all the eat methods are only slightly different, then you can create a base class which will contain the common code and will be invoked from the subclasses through overriden methods which add the different parts. The base class can still implement the interface. Hope it is clear.

提交回复
热议问题