OOP Principles

10. OOP Principles#

Classes alone do not make a program object-oriented. This chapter names and illustrates the four pillars of OOP — encapsulation, inheritance, polymorphism, and abstraction — with concrete C# examples. The goal is conceptual clarity, not deep hierarchies: in modern C#, you will mostly use encapsulation and interfaces. Deep inheritance is often a design smell.

Why this chapter matters

OOP vocabulary is universal — every job interview and every large codebase uses these terms. You should be able to name the four pillars, explain them, and recognize them in code. That said, the industry has shifted: modern C# and Python favor composition and interfaces over deep class hierarchies. Knowing when not to use inheritance is as important as knowing how.

Learning goals

By the end of this chapter, you should be able to:

  • name and explain all four OOP pillars with a concrete example of each

  • formally define encapsulation and relate it to what was practiced in the Classes chapter

  • create a class hierarchy using : BaseClass and override / virtual

  • define and implement an interface or abstract class

  • explain why preferring interfaces and composition over deep inheritance is a modern best practice

Chapter flow