Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

Launch price

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year, or $19.50 for your first year with LAUNCH50, ends 1 Nov, 18:30 UTC.

See plansStart free instead

Module 08 · System Design · Low-level design: classes, properly

Swap the rule, keep the class (Strategy and Factory)

Swap the Rule, Keep the Class
Swap the Rule, Keep the Class · Open board

The elif chain copied into three pages, the four rule cards that replace it, and the table that makes them.

Before you start. You need a few ideas from earlier in this track. A class is a blueprint for objects. A constructor is the code that runs once when an object is made, written __init__ in Python. Has-a beats is-a (composition over inheritance) showed an object keeping another object inside it and passing requests to it, so that part can be replaced later. Five letters, one shop (SOLID) gave the rule called open for extension and closed for editing: add new behaviour by adding code, not by changing code that is already tested. This lesson turns both into two named moves.

Lesson 39 of 73 in System Design

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year, or $19.50 for your first year with LAUNCH50, ends 1 Nov, 18:30 UTC.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 1987: a workshop paper about an architect’s idea
  • The pain: an if/else chain that only grows
  • The fix: a strategy, one class per rule
  • A new question: who picks the class?
  • Handing the rule in: dependency injection
  • Not every if is a problem

Terms it explains: design pattern, strategy, extension point, factory, dependency injection.

Review System Design