OCP kata overview
Upcoming SlideShare
Loading in...5
×
 

OCP kata overview

on

  • 343 views

 

Statistics

Views

Total Views
343
Slideshare-icon Views on SlideShare
343
Embed Views
0

Actions

Likes
0
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    OCP kata overview OCP kata overview Presentation Transcript

    • 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 for modification” that is, such an entity can allow its behaviour to be modified without altering its source code
    • 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 make the test pass.  The factory should be limited to creating objects and linking them together.  No conditionals allowed in the factory.
    • Factory test example @Test public void simpleAddition() { Calculator calc = new CalculatorFactory().create(); assertEquals(7, calc.eval(“3 + 4”)); }
    • 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 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!)
    • 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