Beyond design patterns and principles - writing good OO code
summary
Practical rules for better OO: favor wrap primitives into value objects (email, money, coordinates) to enforce validation and cohesion; require complete state in constructors and avoid setter parties; apply CQS: commands void, queries return values and validate state transitions with exceptions and postconditions; prefer composition over inheritance and inject behavior via constructor (e.g., exchange-rate service or dice provider) so tests control behavior; use static analysis like PHPStan/Psalm and stricter types to catch mixed return types and make failures loud rather than hidden.
AI-written summary · about
chapters (25)
- 0:00Beyond Design Principles & Patterns
- 0:56Writing good OO code
- 1:11Design patterns
- 3:08Design principles, and more patterns
- 4:35Education
- 7:22Objects introduce meaning
- 10:10Objects keep together what belongs
- 11:04Cohesion
- 11:48Objects bring together meaningful behaviors
- 16:23For all objects
- 16:59At construction time
- 18:28At modification time
- 18:54What's the "right" data?
- 22:02Command/Query Separation
- 24:34CQS principle
- 25:04Return single-type values
- 27:03At failure time
- 27:19Offensive programming
- 31:53State versus behavior, revisited
- 33:29Treat your objects as black boxes
- 34:45Don't test constructors by calling getters
- 38:22Changing the behavior of an object
- 40:55Composition over inheritance
- 41:17Guiding experiment
- 42:19Create better objects
related talks
57mCore Software Design Principles for Programmers
27mObject Oriented Programming Best Practices
51mFunctional Principles for Object Oriented Development
45mOOP revisited
48mMy Style Guide for Object-Oriented Design
34mPHP, Value Objects and You 🫵
47mExpressing Design in Code: Architecturally-Evident Coding Patterns
36mAn Introduction to OOP, Design Patterns, and TDD
