Roadmap › 1. .NET › Step 10
OOP

OOP Concepts in C#

Classes and objects, the four pillars (encapsulation, abstraction, inheritance, polymorphism), interfaces vs abstract classes, composition and object relationships.
What it is & where it is used

Object-Oriented Programming (OOP) organises code around objects — bundles of data (state) and behaviour (methods) — instead of loose functions and global data. C# is designed around OOP, and every .NET interview tests it.

The four pillars:

PillarOne lineC# features
EncapsulationHide internal state; expose a controlled APIprivate fields, properties, access modifiers
AbstractionShow what an object does, hide howinterface, abstract class
InheritanceReuse and extend a base type ("is-a"): BaseClass, virtual/override, sealed
PolymorphismOne interface, many implementationsOverloading (compile time), overriding (runtime)
Versions & history

OOP is a paradigm, not a versioned product, but C# has added OOP-related features over time:

C#OOP-related additions
1.0Classes, interfaces, inheritance, virtual/override, abstract, sealed, properties, events
2.0Generics, static classes, partial classes
3.0Auto-properties, object initialisers, extension methods
8.0Default interface methods (interfaces can contain implementations)
9.0Records (value equality), init accessors, covariant return types
11required members, static abstract members in interfaces
12Primary constructors for classes and structs
14Extension members (extension properties)

History: Simula 67 introduced classes; Smalltalk (1970s) popularised "everything is an object"; C++, Java and C# made OOP mainstream.

Lifecycle

Object lifecycle in .NET

  1. Type loading — the first time a type is used, the CLR loads it and runs its static constructor once.
  2. Allocation — new reserves memory on the managed heap (value types: inline).
  3. Construction — field initialisers run, then base-class constructor, then the derived constructor body (: base(...) / : this(...) chaining).
  4. Use — methods called, state changes through its public API.
  5. Unreachable — no references remain.
  6. Collection — GC reclaims memory; a finaliser runs first if defined.
  7. Disposal (optional, deterministic) — Dispose() via using releases unmanaged resources earlier.

OOP design lifecycle (OOAD): requirements → identify nouns (classes) and verbs (methods) → define responsibilities and relationships (UML class diagram) → apply principles (SOLID) and patterns → implement → unit test → refactor.

Tools used to develop
  • Visual Studio Class Designer / Class Diagram — visualise classes and inheritance.
  • UML tools — draw.io, PlantUML, Mermaid, StarUML, Lucidchart.
  • ReSharper / Rider — refactorings: extract interface, pull members up, introduce parameter object.
  • SharpLab.io — see what the compiler generates (records, primary constructors).
  • xUnit + Moq/NSubstitute — test classes through interfaces.