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

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.

主站蜘蛛池模板: 科技| 淄博市| 宁明县| 明光市| 岑巩县| 玉龙| 湟中县| 阿勒泰市| 永寿县| 自贡市| 饶阳县| 拉孜县| 商丘市| 昌都县| 紫金县| 孟津县| 禄丰县| 丽江市| 新蔡县| 武鸣县| 古田县| 汶上县| 宁河县| 太谷县| 四会市| 石门县| 新竹县| 宁阳县| 汝阳县| 通江县| 双江| 临泉县| 夏邑县| 漳平市| 资兴市| 张家界市| 耒阳市| 剑河县| 昌宁县| 绥棱县| 苍南县|