Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Object Invariants,
Immutability & You
Making Objects Do Your Bidding
AmsterdamPHP 15-01-2015
Jeroen v.d. Gulik
• CTO / Co-Founder Isset (http://isset.nl)
• Builder of Artificial Stupidity
• @n0x13
• Likes Cats … a l...
Isset Internet Professionals
• We build custom internet technology based solutions
• We helped design and build several on...


“Every Great Talk should
start with a Great Quote”

- Ross Tuck
-
-House M.D.
Telephone Game
“Over time, the original
intent and purpose
gets lost”
- Jeroen v.d. Gulik
“A Customer should
always have an email
address”
Testing shows the
presence, not the absence
of bugs.
- Joseph Stalin
“We should enforce
(business) rules when
creating objects”
- Mao Zedong
“A Customer should have
a valid email address”
Outside-in validation
should be avoided

- Albert Einstein
Objects should be
responsible for their own
internal consistency
- Barack Obama
● Single Responsibility Principle
● Duplicate code
Design by contract
Value Object
● Small Objects
● Equality based on value
● Immutable
Entity Object
● Usually big(-ger)
● Equality based on Identity
● Mutable
● Can change over time
Immutability
● Simplifies code
● Less cognitive load
● Guaranteed consistent
● Referencing without breakage
● Easy to test...
Immutable Object,
Best Object
- The Hulk
“A Customer should have a
valid email address and a
password”
Make the Implicit,
Explicit
Objects as dumb data
stores

This is our industry standard
Published ?
Objects should have
behaviour attached 

to them
- Julius Caesar
Objects should tell a tale about its
current state and all the possible
ways to change that state
- Bruce Lee
Schrödinger's cat
UnpaidOrder PaidOrder
“Sounds like a State Machine”
- Igor Wiedler
Immutability
UnpublishedArticle PublishedArticle
UnpublishedArticle PublishedArticle
Draft Article
Draft Article RetractedArticle
Objects should only expose
methods relevant to it's
current state
- George Bush
Objects should …
• Be responsible for their own internal state
• Have specific behaviour towards its responsibility
• Broa...
Magic is bad, hmmmkay
- Saddam Hussein
Questions?
Please rate my talk: https://joind.in/event/view/
3267
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Object invariants, immutability & you full talk (v1) - AmsterdamPHP
Upcoming SlideShare
Loading in …5
×

Object invariants, immutability & you full talk (v1) - AmsterdamPHP

769 views

Published on

Code tells a story, but is it the actual story the original author wanted to tell? A lot of time the original story gets lost, as new functionality gets bolted on, or key parts are extracted, leaving behind an incomplete picture. These repurposed objects might pass all the unit tests but have no actual meaning in the context of the original story. We will take a look at how we can more easily communicate the purpose of code to future developers, by introducing contracts and immutability, and using explicit context bound language, to give meaning to the code and keep the story whole.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Object invariants, immutability & you full talk (v1) - AmsterdamPHP

  1. 1. Object Invariants, Immutability & You Making Objects Do Your Bidding AmsterdamPHP 15-01-2015
  2. 2. Jeroen v.d. Gulik • CTO / Co-Founder Isset (http://isset.nl) • Builder of Artificial Stupidity • @n0x13 • Likes Cats … a lot
  3. 3. Isset Internet Professionals • We build custom internet technology based solutions • We helped design and build several online video platforms (Pathé Thuis, Videoland, NPO Plus) • Currently focussing on video-transcoder.com • We like a challenge so if you have interesting problems to solve, come and talk to me • Still Hiring
  4. 4. 
 “Every Great Talk should start with a Great Quote”
 - Ross Tuck -
  5. 5. -House M.D.
  6. 6. Telephone Game
  7. 7. “Over time, the original intent and purpose gets lost” - Jeroen v.d. Gulik
  8. 8. “A Customer should always have an email address”
  9. 9. Testing shows the presence, not the absence of bugs. - Joseph Stalin
  10. 10. “We should enforce (business) rules when creating objects” - Mao Zedong
  11. 11. “A Customer should have a valid email address”
  12. 12. Outside-in validation should be avoided
 - Albert Einstein
  13. 13. Objects should be responsible for their own internal consistency - Barack Obama
  14. 14. ● Single Responsibility Principle ● Duplicate code
  15. 15. Design by contract
  16. 16. Value Object ● Small Objects ● Equality based on value ● Immutable
  17. 17. Entity Object ● Usually big(-ger) ● Equality based on Identity ● Mutable ● Can change over time
  18. 18. Immutability ● Simplifies code ● Less cognitive load ● Guaranteed consistent ● Referencing without breakage ● Easy to test ● Caching (profit!)
  19. 19. Immutable Object, Best Object - The Hulk
  20. 20. “A Customer should have a valid email address and a password”
  21. 21. Make the Implicit, Explicit
  22. 22. Objects as dumb data stores
 This is our industry standard
  23. 23. Published ?
  24. 24. Objects should have behaviour attached 
 to them - Julius Caesar
  25. 25. Objects should tell a tale about its current state and all the possible ways to change that state - Bruce Lee
  26. 26. Schrödinger's cat
  27. 27. UnpaidOrder PaidOrder
  28. 28. “Sounds like a State Machine” - Igor Wiedler
  29. 29. Immutability
  30. 30. UnpublishedArticle PublishedArticle
  31. 31. UnpublishedArticle PublishedArticle Draft Article
  32. 32. Draft Article RetractedArticle
  33. 33. Objects should only expose methods relevant to it's current state - George Bush
  34. 34. Objects should … • Be responsible for their own internal state • Have specific behaviour towards its responsibility • Broadcast their state • Only care about the state it’s currently in.
  35. 35. Magic is bad, hmmmkay - Saddam Hussein
  36. 36. Questions? Please rate my talk: https://joind.in/event/view/ 3267

×