SOLID
The Open/Closed Principle
Dependency Inversion
Paul Blundell
@Blundell_apps
www.blundellapps.com
Five basic principles of object-orientated programming.
“The principles when applied together intend to make it more likel...
Five basic principles of object-orientated programming.
“The principles when applied together intend to make it more likel...
Five basic principles of object-orientated programming.
“The principles when applied together intend to make it more likel...
Open / Closed Principle
?
SOLID
Open / Closed Principle
“Software entities (classes, modules,
methods etc) should be open for extension
but closed for mod...
Open Closed Principle
Open Closed Principle
Dependency Inversion
The aim of the OCP kata is to use the Open
Closed Principle to design a maintainable
and extensible code base.
Think about...
Write the first failing test
Then write a factory that returns an object or
a composed object that makes the test
pass.
Ru...
@Test
public void scoreZeroForGutterGame() {
// First test
}
@Test
public void scoreTwentyForAllOnesGame() {
// Second tes...
Write the next failing test
Can you make this test pass by just changing
the factory and object composite?
Yes - Great do ...
Fork / Clone this repo:
git@github.com:novoda/dojos.git
Goto this folder:
github.com/novoda/dojos/tree/master/ocpBowling
M...
Matteo Vaccari
- invented the OCP Kata
- http://matteo.vaccari.name/blog/archives/293
David Nicolette
- created the OCP ji...
Upcoming SlideShare
Loading in...5
×

Open Closed Principle kata

1,024

Published on

Talk and Kata on using the Open Closed principal of SOLID as well as Dependency Inversion to complete the Bowling Kata

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,024
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Open Closed Principle kata

  1. 1. SOLID The Open/Closed Principle Dependency Inversion Paul Blundell @Blundell_apps www.blundellapps.com
  2. 2. Five basic principles of object-orientated programming. “The principles when applied together intend to make it more likely that a programmer will create a system that is easy to maintain and extend over time” S ? O ? L ? I ? D ? SOLID
  3. 3. Five basic principles of object-orientated programming. “The principles when applied together intend to make it more likely that a programmer will create a system that is easy to maintain and extend over time” Single Responsibility Principle Open / Closed Principle Liskov’s Substitution Interface Segregation Dependency Inversion SOLID
  4. 4. Five basic principles of object-orientated programming. “The principles when applied together intend to make it more likely that a programmer will create a system that is easy to maintain and extend over time” Single Responsibility Principle Open / Closed Principle Liskov’s Substitution Interface Segregation Dependency Inversion SOLID
  5. 5. Open / Closed Principle ? SOLID
  6. 6. Open / Closed Principle “Software entities (classes, modules, methods etc) should be open for extension but closed for modification” That is such an entity can allow its behaviour to be changed without altering its source code. SOLID
  7. 7. Open Closed Principle
  8. 8. Open Closed Principle
  9. 9. Dependency Inversion
  10. 10. The aim of the OCP kata is to use the Open Closed Principle to design a maintainable and extensible code base. Think about: - How to compose functionality out of existing objects - How to avoid reworking existing code OCP Kata
  11. 11. Write the first failing test Then write a factory that returns an object or a composed object that makes the test pass. Rules: - the factory should be limited to creating and linking objects - no conditionals allowed in the factory OCP Kata
  12. 12. @Test public void scoreZeroForGutterGame() { // First test } @Test public void scoreTwentyForAllOnesGame() { // Second test } // Continue Bowling OCP Kata
  13. 13. Write the next failing test Can you make this test pass by just changing the factory and object composite? Yes - Great do it! No - Refactor until you can The refactoring should be the system to a state where it’s possible to implement the next test just by changing the composite of objects that is returned by the factory. Do not implement new functionality when refactoring the current test must still fail. OCP Kata
  14. 14. Fork / Clone this repo: git@github.com:novoda/dojos.git Goto this folder: github.com/novoda/dojos/tree/master/ocpBowling Make a copy of this folder (rename default with a team name): github.com/novoda/dojos/tree/master/ocpBowling/20130918-default Rules are in the repo here: ocpBowling/20130918-default/src/main/java/com/bowling/bowling_rules.txt Start! OCP Kata
  15. 15. Matteo Vaccari - invented the OCP Kata - http://matteo.vaccari.name/blog/archives/293 David Nicolette - created the OCP jigsaw diagram Uncle Bob - Creator of the original bowling Kata - http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata Kevin Rutherford - guided me in the art of Kata’s - http://silkandspinach.net/ Jonas Gauffin - for the meme - http://blog.gauffin.org/2012/05/solid-principles-with-real-world-examples/#.UjWDy9K_s2k Credits Paul Blundell @Blundell_apps www.blundellapps.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×