官术网_书友最值得收藏!

How it works...

So, you might be wondering what the difference between an abstract class and an interface is. It basically comes down to where you want your implementation. If you need to share functionality between derived classes, then an abstract class is the best fit for your needs. In other words, we had specific things that were common to all cats (lions, tigers, and cheetahs) such as hunting, eating, and sleeping. This is then best used within an abstract class.

If your implementation is specific to a class or several classes (but not all classes), then your best course of action would be to use an interface. In this case, the IPurrable interface can be applied to several classes (for example, cheetahs and domestic cats) but can't be applied to all cats (such as lions and tigers), because not all cats can purr.

Knowing this difference and where you need to place your implementation will aid you in deciding whether you need to use an abstract class or an interface.

主站蜘蛛池模板: 英德市| 文昌市| 海城市| 镇平县| 精河县| 当涂县| 张家口市| 马龙县| 屯留县| 内黄县| 惠来县| 禄劝| 宁城县| 景德镇市| 高唐县| 拉孜县| 青海省| 湟中县| 马关县| 额敏县| 贺兰县| 东乡族自治县| 昆山市| 横峰县| 孝昌县| 平度市| 平和县| 莱州市| 泉州市| 南安市| 金塔县| 内江市| 友谊县| 得荣县| 德清县| 南宫市| 丹凤县| 淮阳县| 天镇县| 汕尾市| 虹口区|