PHP Class Design Guide
About this guide
A 14-chapter guide for PHP engineers who want to learn class design itself, from first principles to practice. The first half builds up class design principles that do not depend on any framework, and the second half applies those principles to real Laravel code. By the end, the goal is to be able to explain common design breakdowns like the Fat Controller and the Fat Model in your own words, and to decide for yourself how to fix them.
What makes this guide different
- Two parts: Part 1 (chapters 1-7) covers class design principles in framework-independent PHP; Part 2 (chapters 8-14) applies them to model and service class design in Laravel
- Focused on judgment: rather than memorizing "the right answer," you practice "why choose this design" through the exercises at the end of each chapter
- Stops at class design: Part 2 stays at class design in Laravel and does not go into layered implementations from DDD or Clean Architecture (see "What this guide does not cover" below)
- Modern PHP assumed: targets PHP 8.2 or later (readonly, enum, constructor promotion) and Laravel 11 or later
How this guide is structured
Chapter outline
Part 1: Class design principles in PHP (framework-independent)
| # | Chapter | Overview |
|---|---|---|
| 01 | Introduction | Why learn class design. Motivation through real examples of god classes and code that resists change |
| 02 | PHP class syntax basics | Properties, methods, constructors, visibility modifiers, readonly, constructor promotion, enum |
| 03 | Encapsulation and information hiding | The danger of public properties, tell-don't-ask, and deciding whether you need getters and setters |
| 04 | The single responsibility principle | Keeping classes small. Signs of a god class and a worked example of splitting responsibilities |
| 05 | Inheritance and composition | is-a versus has-a, and why composition is preferred over inheritance |
| 06 | Interfaces and depending on abstractions | Designing against contracts, as the entry point to dependency inversion |
| 07 | Cohesion, coupling, and SOLID in review | Where Part 1 comes together. Fills in O/L/I and revisits all five SOLID principles through cohesion and coupling |
Part 2: Class design in practice with Laravel
| # | Chapter | Overview |
|---|---|---|
| 08 | Introducing Part 2 | What Fat Controller and Fat Model mean, and the scope of this part (class design only) |
| 09 | Responsibilities of an Eloquent model | How to decide which responsibilities belong in a model and which do not |
| 10 | Splitting responsibilities into service classes | How to decide when to extract processing into a Service class as a controller grows |
| 11 | Dependency injection and the Laravel container | How to put the interface design from Part 1 into practice in Laravel |
| 12 | Exception design and validation | Custom exception classes, the basics of Form Request, and fail-fast design |
| 13 | Practice: refactoring class design | A before-and-after on a Fat Controller and Fat Model that puts every Part 1 principle to work |
| 14 | Summary | A checklist for making your own calls at work, and where to go next |
Who this is for
- PHP engineers who want to learn the basic principles of class design systematically (Part 1 requires no Laravel experience)
- Laravel engineers who feel the pain of Fat Controllers and Fat Models
- Anyone who found A Practical Guide to Laravel × DDD × Clean Architecture hard going and wants to shore up the fundamentals first
Prerequisites
| Requirement | Knowledge | Scope |
|---|---|---|
| Required | Basic PHP syntax (variables, functions, control flow) | All 14 chapters |
| Not required | Experience with class design | All 14 chapters (this guide starts from the basics) |
| Part 1: not required / Part 2: required | Laravel's basic MVC structure, routing, and basic CRUD with Eloquent | Chapter 8 onward (if you are unsure, follow the prerequisite links given at the start of chapter 8) |
How to read it
- New to class design entirely: read Part 1 in order and check your understanding with the exercises at the end of each chapter
- Comfortable with the basics, in a hurry to apply them in Laravel: skim Part 1 and start properly at chapter 8
- Using it as a reference: open the relevant chapter directly from the outline above
What this guide does not cover
- DDD tactical patterns (value objects, entities, aggregates, the repository pattern, and so on) — covered by A Practical Guide to Laravel × DDD × Clean Architecture
- Layered Clean Architecture implementations (the use case layer, the presentation layer, managing transaction boundaries, and so on) — same guide
- An introduction to the Laravel framework itself (how to write routes, basic Eloquent operations, and so on) — Part 2 assumes you have already used these
Related guides
- A Practical Guide to Laravel × DDD × Clean Architecture — the practical follow-on for the DDD and Clean Architecture material this guide leaves out
- Clean Code Guide — Classes — how to think about class design in TypeScript (a different language, but the principles carry over)
- Clean Code Guide — SOLID principles — the SOLID principles explained in TypeScript