Software Engineering Architecture Lab

Level 3: Object-Oriented Design

Design classes and interfaces so new requirements mean adding code, not editing fragile code. Level 3 of 11: 6 lessons on object-oriented design.

Outcome: Design classes and interfaces so new requirements mean adding code, not editing fragile code.

ShopFlow adds payments, discounts and shipping. The principles behind good object design — SOLID, composition, encapsulation — decide whether each new feature is a small addition or a risky edit.

The pressure on ShopFlow: Every new payment method or discount means editing the same huge classes.

Lessons in level 3

  1. Single Responsibility: One Reason to Change — A class should answer to one group of people with one kind of change.
  2. Open/Closed: Add Features Without Editing Old Code — Extend behaviour through new classes instead of growing if/else chains.
  3. Liskov Substitution: Subtypes That Keep Their Promises — When a subclass surprises its callers, inheritance becomes a trap.
  4. Interface Segregation & Dependency Inversion — Small interfaces owned by the caller, and business logic that does not depend on infrastructure.
  5. Composition Over Inheritance — Assemble behaviour from parts instead of building deep class trees.
  6. Encapsulation, Tell Don’t Ask & the Law of Demeter — Put behaviour next to the data it protects, and stop reaching through objects.

Source books

Other levels