Beyond design patterns and principles - writing good OO code
summary
Argues that good OO means wrapping primitives into types, enforcing complete, coherent state at construction, and preferring composition over inheritance so behavior changes by injection not subclassing. Recommends constructor injection only, no optional setters, fail early with exceptions, and strict return types (empty lists not null). Separates mutations from queries with command vs query. Use static analysis and tools like PHPStan at max level and "safe" wrappers to spot functions that return false so failures become loud and debuggable.
AI-written summary · about
chapters (24)
- 0:00Introduction to talk
- 0:24Beyond design patterns
- 1:09Problems with design patterns
- 3:18Back to basics of OOP
- 4:21Primitive types and objects
- 6:07Good class design principles
- 8:15Wrapping primitive values
- 10:03Combining values into objects
- 11:29Objects attracting behavior
- 12:32State versus behavior in objects
- 13:57Types of objects diagram
- 15:03Consistent object states
- 16:50Constructor and setter injection
- 18:14Validating input and state
- 19:39Fail early in methods
- 21:25Command query separation
- 23:59Return types and exceptions
- 25:44Offensive programming approach
- 26:51Static analysis tools
- 28:35Hiding implementation details
- 29:57Testing objects as black boxes
- 32:29Composition over inheritance
- 35:15Summary of best practices
- 36:44Q&A session
