Abstraction
Abstraction focuses on exposing only the essential features of an object or system to the user, while hiding the complex implementation details. It answers what an object does, rather than how it does it. In C#, abstraction is primarily achieved through abstract classes and interfacesInterfaces versus abstract classesTwo ways to define what a type must offer, and when each one fits.Opens in a new tab.
In C#
Consider an abstract class Vehicle that defines an abstract void Drive() method. Derived classes like Car or Motorcycle must provide their specific implementations for Drive(). Users interacting with a Vehicle object only need to know about the Drive() capability, not the specific mechanics of how each vehicle type drives.
The abstract members are in the first class. Car provides the implementations.
public abstract class Vehicle{ public abstract void StartEngine(); // Essential feature public abstract void StopEngine(); // Essential feature public abstract void Drive(); // Abstract method, details hidden} public class Car : Vehicle{ public override void StartEngine() { Console.WriteLine("Car engine started."); } public override void StopEngine() { Console.WriteLine("Car engine stopped."); } public override void Drive() { Console.WriteLine("Car is driving on four wheels."); }}Where it matters
Abstraction simplifies the understanding and usage of complex systems. By hiding unnecessary details, it reduces the cognitive load on developers who use the abstracted components, and it promotes loose coupling between parts of a system. That makes maintenance and evolution easier, since changes to the hidden implementation details don’t affect client code as long as the abstract interface stays consistent.
It works together with encapsulationEncapsulationKeep an object's data private, and let the outside world reach it only through members you choose.Opens in a new tab.
Sources
- C# Object Oriented (How It Works For Developers), IronPDF · accessed May 16, 2025