- 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.
- Spring 5.0 Microservices(Second Edition)
- Flash CS6中文版應用教程(第三版)
- 假如C語言是我發明的:講給孩子聽的大師編程課
- MySQL數據庫管理與開發(慕課版)
- ASP.NET 3.5程序設計與項目實踐
- Python算法從菜鳥到達人
- 微信小程序項目開發實戰
- Android開發案例教程與項目實戰(在線實驗+在線自測)
- C#實踐教程(第2版)
- Python算法指南:程序員經典算法分析與實現
- 基于Struts、Hibernate、Spring架構的Web應用開發
- 從零開始學Linux編程
- 51單片機C語言開發教程
- Node.js:來一打 C++ 擴展
- Multithreading in C# 5.0 Cookbook