Open/closed principle 00:00:00 Make a prediction You will find a genuine axis of variation and add a shipping rate without editing each checkout branch. An overnight method is added to a switch that appears in three checkout screens. What will happen if one screen is missed? The same order gets inconsistent quotes depending on where it was placed. Give the quote calculation a shared boundary, then supply the overnight rule at that boundary. 00:00:27 Noor, Lee and the wall A workshop wall has powered sockets. Adding a lamp plugs into an existing socket rather than pulling up the wall. A device drawing more current than the socket permits cannot be safely plugged in just because it fits. Define the particular kind of change a contract supports. Extensions must meet both the shape and the promises of that opening. The open/closed principle (OCP) says that a class, a module or a function should be open for extension and closed for modification. Open: you can make it do something new. Closed: you do that without editing its tested code. Every edit to working code can break what worked. If ten kinds of discount live in one method, a change for the eleventh puts all ten at risk, and all ten must be tested again. If each lives in its own class, the change adds one class and one test. 00:01:25 Add an overnight shipping option Checkout has a growing switch for standard, express and pickup shipping. Every new option risks an unrelated existing branch. Extract the recurring operation: give me a quote for this basket and destination. Put each pricing rule behind that contract. Register an overnight rule. Existing checkout behaviour stays covered by the prior tests; the new tests concentrate on the overnight calculation and wiring. Run the old standard quote before and after registering overnight shipping. Its answer should be identical. Then quote the same basket using overnight. If you must edit every checkout call site to add that option, the point of variation still lives in too many places. 00:02:11 Choose the variation deliberately If a form has only one stable tax rule, adding a registry and plugin discovery may cost more than editing one function. Wait for a real axis of change. An extensible design should simplify the next likely requirement, not every change one can imagine. Try writing a second implementation without inventing a requirement. If it would merely copy the only existing formula, the extension point has no current payoff. A clear pricing function can remain until real variation tells you what information the future policy actually needs. If a new shipping option needs fundamentally different data, an old contract may need revision. Open for one variation does not mean open for every possible change. If the rule has never varied and no independent extension exists, begin with one clear function. VS Code. An extension declares contribution points (commands, menus, languages, themes) as JSON in its package.json. The editor reads the declarations and is not edited for an extension. Chrome extensions. Extensions customise the interface, observe browser events and change pages, without a change of the browser. 00:03:27 Try an interview follow-up Marketing wants to create rules without releases. How far do you go? I would let marketing combine a deliberately small set of tested rule blocks. Each change should validate as a whole, run against representative carts, and leave a record of the version that priced an order. If a new request cannot be expressed safely using those blocks, it deserves an ordinary reviewed release. Yesterday's orders refer to a rate policy that the shop retires today. Can you delete that policy as soon as new checkout stops selecting it? First establish how earlier quotes are reproduced. Store the agreed price and policy version or preserve a compatible calculation path. The extension point for new orders does not by itself preserve the historical commitments already issued. 00:04:24 What to take with you Find the axis that keeps changing, put a small contract on it, let the core call only the contract, and switch new pieces on in one place. A new discount is then a new class and one line of wiring. You cannot be closed against everything. Choose the axis from evidence, usually the second or third change of the same kind. Until then a plain if is the better design.