Successfully reported this slideshow.
Your SlideShare is downloading. ×

OCP kata overview

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Coding standards
Coding standards
Loading in …3
×

Check these out next

1 of 13 Ad

More Related Content

Similar to OCP kata overview (20)

Advertisement

Recently uploaded (20)

Advertisement

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

×