Posted in Abstract Class, C#, Interface, Object Oriented Programming

C# – Abstract Class vs Interface

Abstract Class Interface
Multiple inheritance Doesn’t support support
Data Member contains Doesn’t contain
Constructor declaration contains Doesn’t contain
Definition May contain definition with no implementation Just a pattern, an empty shell
Methods Can have both abstract & non-abstract methods Can only have abstract methods
Implementation Can contain both definition and its implementation

Incomplete class, cannot be instantiated

Can only have the signature of the functionality without any code
Access Modifier Can have all access modifiers for member declaration of functions, subs and properties. Not allowed (all methods must be implicitly defined as public).

All the members assumed as implicitly public.

Homogeneity is used for implementations of the same type, behavior and status Is used for implementations that share only method signatures
Declaration Acts as a base class for all other classes, can declare/ use any variable Not allowed to declare any variables
Core vs Peripheral Core identity of a class & for objects of the same data type Used to define Peripheral ability of a class
Rigid vs Supple More supple More rigid
Fields definition Predefined fields & constants Fields cannot be defined in interfaces
Posted in Abstract Class, C#, Concrete Class, Object Oriented Programming

Abstract classes vs Concrete Classes

 

Abstract Class Concrete Class
Type Base class Default class
Methods May contain partially implemented methods All methods are completely implemented
Functions Some or all declared functions are purely virtual No purely virtual functions
Instantiation Cannot be instantiated Can be instantiated

Image Courtesy: tutorials.jenkov.com, stackoverflow.com