Abstract Class | Interface |
Cannot instantiate. | Cannot instantiate. |
Can only be used to derive. | Can only be used to derive. |
Can contain data and/or implementation in the form of concrete methods. | No data, no implementation. (All methods/virtual functions must be abstract/pure.) |
In C#: declare both class and abstract methods with abstract keyword. | In C#: declare class with interface keyword. All methods become virtual. |
In C++: declare at least one pure virtual function using "= 0" syntax. Can use destructor, too. | In C++: no concept of interface built into C++; interface is a design pattern you must follow. |
Use when you want to provide a partial implementation with some functions omitted. | Use when you want to define the abstract qualities of a thing, the methods a class must implement to "be" that thing. |
0 Comments