Skip to main content
AmigoFish

This Design Pattern Scares Me To Death

From ArjanCodes · · 29 min

The player loads from YouTube only when you click. It uses YouTube's privacy-enhanced mode.

If the video does not play, the owner may have turned off embedding. Watch it on YouTube instead.

Watch on YouTube

Not rated yet

Description

👉 Get real-time, search result data from Google, Youtube and more with SerpApi: https://serpapi.link/arjan-codes-jan-2025.

Business rules have a nasty habit of spreading across your codebase: copied into APIs, reports, scripts, and slowly drifting out of sync. In this video, I start with a very real, very messy example of duplicated if-statements and show how it escalates into bugs and confusion. Then I refactor it step by step using the Specification Pattern, in a practical, Pythonic style that lets you compose rules, test them in isolation, and even turn your logic into data that can live in config files.

🔥 GitHub Repository: https://git.arjan.codes/2026/spec.

🎓 ArjanCodes Courses: https://www.arjancodes.com/courses.

💬 Join my Discord server: https://discord.arjan.codes.

⌨️ Keyboard I’m using: https://amzn.to/49YM97v.

🔖 Chapters: 0:00 Intro 0:49 What is the Specification Pattern 3:47 The Goal: Reusable, Composable Rules 4:21 Step 1: The Simplest Possible Predicate 13:56 Step 2: Make Defining Predicates Pleasant 16:48 Step 3: Generalize With Generics and Rule Factories 20:00 Step 4: A Single @Rule Decorator for All Rules 24:54 Step 5: Composing Rules in the User Domain 25:36 Step 6: Loading Rules From Config (Real Specification Power) 28:30 Final Thoughts

#arjancodes #softwaredesign #python

Back to ArjanCodes · Report a problem