BACK
TOP
DotNet - Best Practices – Abstract Class
Matías Creimerman - Buenos Aires, Argentina - 2020-02-17

Abstract classes are those that are defined to group together class group types. They are not instantiated, since they only represent the "abstract" of that class group and have properties and methods that that class group that inherits it must define since they belong to that group. An example would be "GeometricFigure" that defines issues common to several geometric figures (calculate area, calculate perimeter, etc) and then each class that inherits from it implements them (triangle, square, etc).

As good practice, it is not allowed to define public or protected internal constructors, since the abstract class does not represent objects and should not be instantiated. You can define protected constructors and internal constructors (not both). If they are only protected, the classes they inherit can delegate a construction to their base class. If they are only internal, limit only this type of construction delegation to its base class within the same assembly. At least 1 class must exist that inherits from the abstract class (but even so it can be rare, at least 2 should exist).

This content is property of Matias Creimerman
Any misuse of this material will be punishable
This work is licensed under a
Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License
Creative Commons License