Skip to main content
PProfileMatch

Object-Oriented Programming Tutorial

Classes, encapsulation, inheritance, polymorphism and SOLID, explained with runnable Python and Java

Beginner to Intermediate4 lessonsabout 25 min of reading

This course is for people who can write functions and loops but find object-oriented programming (OOP) vague: what a class is really for, when to inherit, why interviewers keep asking about SOLID. The ideas are language-agnostic, so the lessons show them in Python and Java, whichever makes the idea clearest, and every example is complete and was run to produce the output shown.

You will learn to design a class around an invariant it must protect, to choose between inheritance and composition using a concrete failure (the fragile base class), to use polymorphism and interfaces so that new behaviour is an addition rather than an edit, and to refactor a tangled class using the SOLID principles without over-engineering it.

The lessons build on each other in that order: classes and encapsulation, inheritance versus composition, polymorphism and abstraction, then a worked SOLID refactor that uses all three. If you are brand new to a language, pair this with the Java course or Python Fundamentals. When you finish, the natural next step is Design Patterns.

Object-Oriented Programming lessons

  1. 1Object-Oriented Programming: Classes, Objects and EncapsulationLearn object-oriented programming basics: classes, objects and how encapsulation protects invariants, with a runnable Python metro-card example.5 min read
  2. 2Inheritance vs Composition in OOP: Which to Use and WhyInheritance vs composition in object-oriented programming: the fragile base class problem, building behaviour from parts, and a practical decision guide.6 min read
  3. 3Polymorphism, Abstraction and Interfaces in OOP (Java Examples)Learn polymorphism, abstraction and interfaces in object-oriented programming with a parking-garage fee engine in Java, plus duck typing and ABCs in Python.7 min read
  4. 4SOLID Principles in Python: A Realistic Refactor, Step by StepApply the SOLID principles to a real refactor: split a tangled invoice class, open it for new plans, inject dependencies and fix a Liskov violation.7 min read

Preparing for an interview? Practise Java interview questions

Learning Object-Oriented Programming to land a job? Browse open roles or check which skills are trending.