About this course
About this course
This free course teaches you to write clean, maintainable code - the part of programming that separates code that works today from code you can still change a year from now. You'll start with the ideas every good design rests on: coupling, cohesion and code smells.
From there you'll master the principles that guide day-to-day decisions - SOLID, KISS, DRY, YAGNI - and then the classic Gang of Four design patterns: creational, structural and behavioral, each with a small, realistic example. The later chapters show the patterns you already use in a modern framework, when a pattern is the wrong choice, and how to refactor messy code toward a clean design.
Every lesson builds on the previous one, with short PHP examples you can read and adapt - though the principles apply in any object-oriented language. By the end you'll recognize good and bad design on sight, and reach for the right tool instead of the nearest one.
It's written for developers who can already write code and now want to write it well.
Course curriculum
- What is software design? What software design really means: readable code, easy change and low maintenance cost. The difference between code that runs and code you can safely change.
- Coupling and cohesion Low coupling and high cohesion are the two lenses for judging any design. See what each means with a small before/after PHP example you can follow.
- What are code smells? A code smell is a hint that something may be off in your code, not a rule you broke. What smells are, with named examples like long method and duplicated code.
- How to read this course The difference between design principles and design patterns, why the examples are PHP, and why patterns are tools, not goals. Read this before you dive in.
- KISS - Keep It Simple The KISS principle in plain terms: prefer the simplest code that works. Why clever one-liners are a liability, shown with a simple vs over-clever PHP example.
- DRY - Don't Repeat Yourself The DRY principle done right: one source of truth per piece of knowledge - plus the trap where a wrong abstraction costs more than a little duplication.
- YAGNI - You Aren't Gonna Need It The YAGNI principle explained: building for speculative future needs is a cost, not an investment. Where over-engineering hides, with a clear PHP example.
- Composition over inheritance Why composition over inheritance holds up as systems grow: has-a beats deep is-a, the fragile base class problem, and a PHP example swapping one for the other.
- The Law of Demeter The Law of Demeter, made practical: don't talk to strangers, avoid long a->b->c->d chains, and apply Tell, Don't Ask. With a clear PHP example.
- Separation of concerns Separation of concerns, made concrete: each class handles one job. Why mixing business logic, persistence and formatting makes code hard to change, in PHP.
- What is SOLID? SOLID is five object-oriented design principles - SRP, OCP, LSP, ISP and DIP. Learn what each stands for and why they make code easier to change.
- Single Responsibility Principle (SRP) The Single Responsibility Principle says a class should have one reason to change. Learn SRP with a clear PHP before-and-after refactoring example.
- Open/Closed Principle (OCP) The Open/Closed Principle says code should be open to extension but closed to modification. Learn OCP in PHP by replacing a growing switch with new types.
- Liskov Substitution Principle (LSP) The Liskov Substitution Principle says a subtype must work anywhere its base type works. Learn LSP with the classic Rectangle/Square PHP example.
- Interface Segregation Principle (ISP) The Interface Segregation Principle says prefer many small interfaces over one fat one. Learn ISP in PHP so classes never implement methods they don't use.
- Dependency Inversion Principle (DIP) The Dependency Inversion Principle says depend on abstractions, not concretions. Learn DIP in PHP by injecting an interface instead of a concrete class.
- SOLID in practice Apply SOLID principles together in one worked PHP refactoring - split responsibilities, invert dependencies and open the code to extension step by step.
- What are design patterns? Learn what software design patterns are, where the Gang of Four came from, and the three categories: creational, structural and behavioral.
- Factory Method Learn the factory method pattern in PHP: move object creation behind a method so callers depend on an interface, not a specific new Concrete().
- Abstract Factory Learn the abstract factory pattern: create whole families of related objects that belong together, and when the extra layer is worth it.
- Builder Learn the builder pattern in PHP: assemble a complex object step by step with a readable fluent API instead of a huge, confusing constructor.
- Singleton Learn the singleton pattern in PHP, then the honest reasons it's often an anti-pattern: global state, hard testing, and why DI usually beats it.
- Prototype Learn the prototype pattern in PHP: copy an existing configured object with clone instead of rebuilding it from scratch, and handle __clone safely.
- Adapter - Make an Incompatible Class Fit Learn the adapter pattern: wrap a class with a mismatched interface so it fits the one your code expects. Adapt a payment gateway in PHP.
- Decorator - Add Behavior by Wrapping Learn the decorator pattern: wrap an object to add behavior without subclassing, and stack decorators. Add caching and logging in PHP.
- Facade - A Simple Front Over a Subsystem Learn the facade pattern: hide a complex subsystem behind one clean method. See a PHP example and how it differs from a framework Facade.
- Composite - Treat a Tree Uniformly Learn the composite pattern: handle leaves and containers through one interface so a whole tree behaves like a single object. PHP example.
- Proxy - Control Access to an Object Learn the proxy pattern: a stand-in with the same interface that controls access to the real object - lazy loading, caching, access checks.
- Bridge - Split Abstraction From Implementation Learn the bridge pattern: separate an abstraction from its implementation so both vary independently and avoid a class explosion. PHP example.
- Strategy Pattern Learn the Strategy pattern in PHP: put each algorithm behind an interface and pick one at runtime, replacing a growing if/switch and honoring OCP.
- Observer Pattern Learn the Observer pattern in PHP: a subject notifies subscribers when something happens, keeping the event and the reactions loosely coupled.
- Command Pattern Learn the Command pattern in PHP: wrap a request as an object with an execute method to enable queues, logging, retries and undo.
- Template Method Pattern Learn the Template Method pattern in PHP: a base class defines the steps of an algorithm and subclasses fill in the parts that differ.
- State Pattern Learn the State pattern in PHP: give each state its own class so an object changes behavior as its state changes, instead of scattered if/else.
- Chain of Responsibility Pattern Learn the Chain of Responsibility pattern in PHP: pass a request through a chain of handlers until one handles it - the idea behind middleware.
- Iterator and Mediator Patterns Learn the Iterator pattern in PHP: traverse a collection without exposing its internals, plus the Mediator pattern for taming many-to-many coupling.
- Patterns you already use in Laravel Facades, the container, events, middleware, notifications - the design patterns in Laravel you use every day, named and mapped to the Gang of Four.
- Dependency injection and the container How dependency injection in Laravel works: type-hint an interface, bind it once, and the service container auto-resolves it via constructor injection.
- The repository pattern The repository pattern in Laravel, with a PHP example and the honest debate: Eloquent is already a repository, so when does the extra layer earn its keep?
- When not to use a pattern Knowing when not to use a design pattern beats knowing the patterns. Avoid over-engineering, the golden hammer, and speculative abstraction in your code.
- Refactoring toward a pattern A worked PHP example of refactoring to the strategy pattern: a growing if/elseif becomes clean classes, step by step. Refactor toward patterns, don't start there.
- A catalog of common code smells A catalog of PHP code smells - long method, god class, duplicated code, feature envy, primitive obsession - each with a one-line tell and its fix.
- Anti-patterns and why they happen The classic anti-patterns - God Object, Spaghetti Code, Golden Hammer, Big Ball of Mud, Copy-Paste Programming - why they emerge and what to do instead.
- Core refactoring techniques Concrete PHP refactoring techniques - Extract Method, Extract Class, Rename, Parameter Object, Replace Conditional with Polymorphism - in small, safe steps.
- A refactoring case study A full before-and-after: refactor one ugly PHP service with a fat, nested method into clean design using SRP, the Strategy pattern and dependency injection.