11. The TDD Rhythm:
1. Quickly add a test
2. Run all tests and see the new one fail
3. Make a little change
4. Run all tests and see them all succeed
5. Refactor to remove duplication
12. The TDD Rhythm:
1. Quickly add a test
2. Run all tests and see the new one fail
3. Make a little change
4. Run all tests and see them all succeed
5. Refactor to remove duplication
15. The “O” in SOLID
• Single Responsibility Principle (SRP)
• Open/Closed Principle (OCP)
• Liskov substitution Principle (LSP)
• Interface Segregation Principle (ISP)
• Dependency Inversion Principle (DIP)
16. The Open/Closed Principle
• You should be able to extend the behavior of a
system without having to modify that system.
https://8thlight.com/blog/uncle-bob/2014/05/12/TheOpenClosedPrinciple.html
17. Open and Closed
Open => we can add behavior just adding new pieces
Closed => we don’t need change old pieces(*)
(*) (no change => no test change, no deploy needed, no
cascading changes )
19. Language libraries
List<Integer> list = ...;
// standard sort
Collections.sort(list);
printAll(list);
// sorting with a specific comparator
Collections.sort(list, new PronounceComparator());
printAll(list);
25. When do we refactor?
Starting code base Changes implemented
red == code changed
(Hopefully) Code cleaned up
Refactor
after
Starting code base Change design to make
room for new feature
Implement feature
Refactor
before
From a slide by Dave Nicolette
27. OCP Kata Rules
1. Write the first failing test
2. Then write a factory that returns an object, or an
aggregate of objects, that make the test pass.
28. The factory should be limited to
creating objects and linking them
together. No conditionals allowed.
29. OCP Kata Rules
1. Write the first failing test
2. Then write a factory that returns an object, or an
aggregate of objects, that make the test pass.
3. Write the next failing test.
30. OCP Kata Rules
1. Write the first failing test
2. Then write a factory that returns an object, or an
aggregate of objects, that make the test pass.
3. Write the next failing test.
4. Make the test pass by changing the factory and/or
adding a new class and nothing else.
31. OCP Kata Rules
1. Write the first failing test
2. Then write a factory that returns an object, or an
aggregate of objects, that make the test pass.
The factory should be limited to creating objects and
linking them together. No conditionals allowed.
3. Write the next failing test.
4. Make the test pass by changing the factory and/or
adding a new class and nothing else.
You can’t? Then refactor your code until you can!
33. The FizzBuzz Game
1, 2, Fizz!, 4, Buzz!, Fizz!, 7,
8, Fizz!, Buzz!, 11, Fizz!, 13,
14, FizzBuzz!, 16, 17, Fizz!...
If the number is a multiple of 3, say “Fizz”
If it is a multiple of 5, say “Buzz”
If it is a multiple of 3 and 5, say “FizzBuzz”
Otherwise, just say the number.