The Open/Closed Principle
S O L I D
The Open/Closed Principle
“software entities
(classes, modules, functions, etc.)
should be open for extension,
but closed ...
adding a new feature
Source: Dave Nicolette
OCP kata
0. Write the first failing test.
Then write a factory that returns an object,
or an aggregate of objects,
that ma...
Factory test example
@Test
public void simpleAddition() {
Calculator calc = new CalculatorFactory().create();
assertEquals...
OCP kata
1. Write the next failing test.
OCP kata
2. Can you make it pass by changing the factory
and/or creating a new class and nothing else?
If yes, great! Go b...
tests
Credits:
Matteo Vaccari invented the OCP kata:
http://matteo.vaccari.name/blog/archives/293
http://www.slideshare.ne...
OCP kata overview
OCP kata overview
OCP kata overview
OCP kata overview
OCP kata overview
Upcoming SlideShare
Loading in …5
×

OCP kata overview

582 views

Published on

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

No Downloads
Views
Total views
582
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

OCP kata overview

  1. 1. The Open/Closed Principle S O L I D
  2. 2. The Open/Closed Principle “software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification” that is, such an entity can allow its behaviour to be modified without altering its source code
  3. 3. adding a new feature Source: Dave Nicolette
  4. 4. OCP kata 0. Write the first failing test. 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 in the factory.
  5. 5. Factory test example @Test public void simpleAddition() { Calculator calc = new CalculatorFactory().create(); assertEquals(7, calc.eval(“3 + 4”)); }
  6. 6. OCP kata 1. Write the next failing test.
  7. 7. OCP kata 2. Can you make it pass by changing the factory and/or creating a new class and nothing else? If yes, great! Go back to 1. If not, refactor until you can. The refactoring should bring the system to a state where it’s possible to implement the next test just by changing the aggregate of objects that is returned by the factory. Be careful not to implement new functionality; the current test must still fail. Remember: no conditionals in the factory. (For extra bonus points: no conditionals anywhere!)
  8. 8. tests Credits: Matteo Vaccari invented the OCP kata: http://matteo.vaccari.name/blog/archives/293 http://www.slideshare.net/xpmatteo/20101125-ocpxpday Dave Nicolette created the jigsaw drawing

×