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

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.

主站蜘蛛池模板: 驻马店市| 山东| 烟台市| 穆棱市| 甘谷县| 平和县| 安徽省| 阿拉善盟| 兴义市| 社会| 开化县| 合山市| 米泉市| 牡丹江市| 和田县| 慈利县| 岳西县| 商都县| 青冈县| 互助| 遵化市| 新宁县| 嘉兴市| 康定县| 旬邑县| 湟源县| 徐水县| 吐鲁番市| 怀来县| 浦东新区| 都兰县| 城市| 岚皋县| 山丹县| 札达县| 邮箱| 湾仔区| 健康| 濉溪县| 个旧市| 博湖县|