2. “
2
The word calisthenics comes from
the ancient Greek words kalòs
(καλός), beauty, and sthénos
(σθένος), strength.
@jesuswasrasta #tac2018
3. “
3
So, here’s an exercise that can help you to
internalize principles of good object-oriented
design and actually use them in real life.
Jeff Bay
@jesuswasrasta #tac2018
4. 4
1. Only one level of indentation per method
@jesuswasrasta #tac2018
15. 15
@jesuswasrasta #tac2018
Board, Row, Circle, Cross?
Too many objects?
Did rules conflicted, sometimes?
Does it felt weird or uncomfortable, maybe?
Debriefing
19. 19
1. Only one level of indentation per method
@jesuswasrasta #tac2018
Single Responsibility Principle (S.O.L.I.D.)
Extract method
Extract objects (collaborators)
20. 20
2. Don’t use ELSE keyword
@jesuswasrasta #tac2018
Polymorphism
Behavioral Patterns
Strategy Pattern (set algorithm at runtime)
State Pattern (state machines)
21. 21
3. Wrap all primitives and strings
@jesuswasrasta #tac2018
Primitive Obsession Anti-Pattern:
using primitives to represent domain ideas
22. 22
4. First class collections
@jesuswasrasta #tac2018
Encapsulation:
Any class that contains a collection
should contain no other member variables
Give behaviors related to the collection a home
23. 23
5. One dot per line
@jesuswasrasta #tac2018
Law of Demeter
Only talk with your immediate friends,
don’t talk to strangers
Fluent interfaces allowed
24. 24
6. Don’t abbreviate
@jesuswasrasta #tac2018
Naming
“Clean Code” book, Robert C. Martin, Ch. 2
Meaningful, intention-revealing,
pronounceable, searchable names
Methos name too long?
Maybe it does too many things...
25. 25
7. Keep all entities small
@jesuswasrasta #tac2018
Single Responsibility Principle (again...)
Class with 50 l.o.c, methods with 5
The “class that fits in the monitor” rule
There’s no black & white, it’s all about trade-offs
26. 26
8. No classes with more than two instance variables
@jesuswasrasta #tac2018
High cohesion, low coupling
27. 27
9. No getters/setters/properties
@jesuswasrasta #tac2018
Tell, don’t ask
Feature envy code-smell
(extensive use of another class)
They violates Open/Closed Principle (S.O.L.I.D.)
Anemic Domain anti-pattern