Abstraction in C#

Abstraction is the process of hiding the details of a particular concept or Object from a user and exposing only the essential features.
Abstraction refers to the act of representing essential features without including the background details or explanations.
Abstraction is the development of Classes,Objects and types in terms of their functionality, instead of thier implementation details.
Abstration simply denotes a model , a view or a representation for an actual item(Class , object or type).
The main characteristics of abstraction is specify into below list

  • Managing the complexity of code.
  • Decomposing complex systems into smaller components.

An abstract class is a class, that no any class can create an object of that class.
The abstract keyword in a class indicates that the class can not be instantiated.

You can create the instance of its derived class (only if it is not marked as abstract).
In C# , you can have a single base class and multiple derived classes.If you do not want that any class can create an object of the base class , you can make the base class as abstract.

Some characteristics of abstract class are as follows.

  • It restricts instantiation ,implying that you can not create an object of an abstract class.
  • Allows you to define abstract as well as non abstract members in it.
  • Requires atleast one abstract method in it.
  • Restricts the use of sealed keyword in it.
  • Possess public access specifier , therefore it can be used any where in a program.

Example by code

Image is not available

An Abstract method is a method which does not provide any implementations , therefore an abstract method does not have method body. It can be declared by using the abstract keyword.
Points to remeber :

  • Abstract method restricts implementation in abstract class.
  • Abstract method allows implementation in a non abstract derived class.
  • Abstract method requires declaration in an abstract class only.
  • abstract method restricts declarartion with Static and Virtual keywords.
  • Abstract method allows to override a Virtual method.

Below is the attached Example of Code

Image is not available

Image is not available

About the Author
Sudheer Singh Chouhan is a Software Engineer having Expertise in Development Design and Architecting the applications , Project Management , Designing Large Scale Databases in SQL Server since last 17 Years.
Skill Sets :- Microsoft .NET technologies like ASP.Net Core, Web API, LINQ, Web Forms, WinForms, SQL Server, EntityFramework, Design Patterns, Solid Principles, Microservices, AWS Cloud.