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

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.

主站蜘蛛池模板: 南江县| 荣成市| 历史| 炉霍县| 上虞市| 海丰县| 福鼎市| 怀化市| 汕尾市| 中超| 河池市| 清水县| 炎陵县| 黑龙江省| 思南县| 大余县| 沙湾县| 阿拉善左旗| 潞城市| 利川市| 岗巴县| 阳曲县| 长兴县| 乡宁县| 会东县| 法库县| 伊春市| 巩义市| 郸城县| 英山县| 重庆市| 申扎县| 香河县| 榆社县| 迁安市| 伊宁县| 玛多县| 中西区| 大渡口区| 普格县| 宜丰县|