- C# 7 and .NET Core Cookbook
- Dirk Strauss
- 171字
- 2021-07-03 00:11:59
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.
- The DevOps 2.3 Toolkit
- Interactive Data Visualization with Python
- 編程珠璣(續(xù))
- Unity Virtual Reality Projects
- 深入理解Java7:核心技術與最佳實踐
- HTML5+CSS3+JavaScript Web開發(fā)案例教程(在線實訓版)
- 基于Swift語言的iOS App 商業(yè)實戰(zhàn)教程
- TypeScript項目開發(fā)實戰(zhàn)
- Mastering JavaScript Design Patterns(Second Edition)
- MySQL從入門到精通(軟件開發(fā)視頻大講堂)
- Internet of Things with ESP8266
- Visual FoxPro 6.0程序設計
- Python Machine Learning Blueprints:Intuitive data projects you can relate to
- Arduino機器人系統(tǒng)設計及開發(fā)
- 零基礎C#學習筆記