- C# 7 and .NET Core Cookbook
- Dirk Strauss
- 230字
- 2021-07-03 00:11:57
Creating and implementing an abstract class
Many developers have heard about abstract classes, but their implementation is a mystery. How can you as a developer identify an abstract class and decide when to use one? The definition is quite a simple one actually. Once you understand this fundamental definition of an abstract class, when and why to use one becomes obvious.
Imagine for a moment that you are developing an application that manages the animals in a cat sanctuary. The cat sanctuary rehabilitates lions, tigers, jaguars, leopards, cheetahs, pumas, and even domestic cats. The common noun that describes all these animals is the word cat. You can, therefore, safely assume that the abstraction of all these animals is a cat, and thus, this word identifies our abstract class. You would then create an abstract class called Cat.
However, you need to keep in mind that you will never ever create an instance of the abstract class Cat. All the classes that inherit from the abstract class also share some functionality. This means that you will create a Lion class and a Tiger class that inherit from the abstract class Cat. In other words, the inherited classes are a kind of cat. Both classes share functionality in the form of Sleep(), Eat(), Hunt(), and various other methods. In this way, we can ensure that inherited classes all contain this common functionality.
- GAE編程指南
- Spring 5.0 By Example
- 造個(gè)小程序:與微信一起干件正經(jīng)事兒
- Learn to Create WordPress Themes by Building 5 Projects
- Django開(kāi)發(fā)從入門(mén)到實(shí)踐
- Java加密與解密的藝術(shù)(第2版)
- 網(wǎng)頁(yè)設(shè)計(jì)與制作教程(HTML+CSS+JavaScript)(第2版)
- Learning jQuery(Fourth Edition)
- Node.js開(kāi)發(fā)指南
- HTML+CSS+JavaScript編程入門(mén)指南(全2冊(cè))
- Laravel Application Development Blueprints
- C++程序設(shè)計(jì)
- VMware vSphere 5.5 Cookbook
- Visual Basic語(yǔ)言程序設(shè)計(jì)上機(jī)指導(dǎo)與練習(xí)(第3版)
- 少兒編程輕松學(xué)(全2冊(cè))