Interface vs Base class

后端 未结 30 3068
甜味超标
甜味超标 2020-11-21 07:34

When should I use an interface and when should I use a base class?

Should it always be an interface if I don\'t want to actually define a base implementation of the

30条回答
  •  没有蜡笔的小新
    2020-11-21 07:45

    Modern style is to define IPet and PetBase.

    The advantage of the interface is that other code can use it without any ties whatsoever to other executable code. Completely "clean." Also interfaces can be mixed.

    But base classes are useful for simple implementations and common utilities. So provide an abstract base class as well to save time and code.

提交回复
热议问题