Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
Object reorientation Christopher Riley Dutch PHP Conference 2018 1
Slide 2
Slide 2 text
Introduction
Slide 3
Slide 3 text
Why? 1
Slide 4
Slide 4 text
Solid
Slide 5
Slide 5 text
Solid • Single responsibility principle 2
Slide 6
Slide 6 text
Solid • Single responsibility principle • Open/closed principle 2
Slide 7
Slide 7 text
Solid • Single responsibility principle • Open/closed principle • Liskov substitution principle 2
Slide 8
Slide 8 text
Solid • Single responsibility principle • Open/closed principle • Liskov substitution principle • Interface segregation principle 2
Slide 9
Slide 9 text
Solid • Single responsibility principle • Open/closed principle • Liskov substitution principle • Interface segregation principle • Dependency inversion principle 2
Slide 10
Slide 10 text
Dry
Slide 11
Slide 11 text
Don’t repeat yourself • Don’t repeat yourself • Don’t repeat yourself • Don’t repeat yourself 3
Slide 12
Slide 12 text
What is the hardest part of software development? 3
Slide 13
Slide 13 text
Reducing bugs
Slide 14
Slide 14 text
Write code which reduces the possible number of invalid states 3
Slide 15
Slide 15 text
Reduce invalid states 4
Slide 16
Slide 16 text
Reduce invalid states 5
Slide 17
Slide 17 text
Reduce invalid states 6
Slide 18
Slide 18 text
An object should always be in a valid state 6
Slide 19
Slide 19 text
Objects should always be valid 7
Slide 20
Slide 20 text
Objects should always be valid 8
Slide 21
Slide 21 text
Encapsulate internal state 8
Slide 22
Slide 22 text
Encapsulate internal state 9
Slide 23
Slide 23 text
Encapsulate internal state 10
Slide 24
Slide 24 text
Use type hints 10
Slide 25
Slide 25 text
Use type hints 11
Slide 26
Slide 26 text
Use type hints 12
Slide 27
Slide 27 text
Change state or return something never both 12
Slide 28
Slide 28 text
Change or return 13
Slide 29
Slide 29 text
Change or return 14
Slide 30
Slide 30 text
Change or return 14
Slide 31
Slide 31 text
Change or return 15
Slide 32
Slide 32 text
Be careful with mutable values 15
Slide 33
Slide 33 text
Mutable values 16
Slide 34
Slide 34 text
Mutable values 17
Slide 35
Slide 35 text
Mutable values 18
Slide 36
Slide 36 text
Knowledge as Code
Slide 37
Slide 37 text
A case study 19
Slide 38
Slide 38 text
A case study • Sort code: 12-34-56 19
Slide 39
Slide 39 text
A case study • Sort code: 12-34-56 • Account number: 12345678 19
Slide 40
Slide 40 text
Basic validation 20
Slide 41
Slide 41 text
Mod 11 validation 21
Slide 42
Slide 42 text
What was the problem? 21
Slide 43
Slide 43 text
What now? 21
Slide 44
Slide 44 text
Rule classes 22
Slide 45
Slide 45 text
The validator 23
Slide 46
Slide 46 text
A value object 24
Slide 47
Slide 47 text
A value object 25
Slide 48
Slide 48 text
The factory 26
Slide 49
Slide 49 text
Conclusion
Slide 50
Slide 50 text
The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise. - Dijkstra 26
Slide 51
Slide 51 text
Thanks • @giveupalready • https://github.com/carnage • https://carnage.github.io • https://joind.in/talk/09ee3 27