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.
Quick revision for interview day. Print it or save it as a PDF.

Four pillars in one line each

  • Encapsulation — private data, public methods that guard rules.
  • Abstraction — interfaces/abstract classes expose what, hide how.
  • Inheritance — Derived : Base reuses and extends ("is-a").
  • Polymorphism — overloading (compile time) and overriding (runtime).

Interface vs abstract class

InterfaceAbstract class
Inherit many?YesNo (one)
State/fieldsNoYes
ConstructorNoYes
Default implementationYes (C# 8+)Yes
Best forContracts, DI, mockingShared base code

Keywords

KeywordMeaning
virtualMay be overridden
abstractMust be overridden; no body
overrideReplaces base virtual/abstract
sealedNo further inheritance/override
newHides a base member (no polymorphism)
baseAccess base members/constructor
thisCurrent instance / chain constructors
staticBelongs to the type

Relationships

  • Association: uses (independent lifetimes)
  • Aggregation: has-a (part survives)
  • Composition: owns-a (part dies with whole)
  • Inheritance: is-a
  • Prefer composition; inherit only for true substitutable "is-a".

Constructor order

Static field initialisers → static ctor (once) → instance field initialisers (derived, then base) → base ctor body → derived ctor body.

Equality checklist

  • Override Equals(object), implement IEquatable<T>, override GetHashCode with HashCode.Combine.
  • Or use record for value equality for free.