Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Xpug Coding Dojo:
 The OCP Kata
Kata
Pairs
Randori
Costraints
The OCP Kata
http://matteo.vaccari.name/blog/archives/293
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.
1. Write the next failing test.
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 agg...
Be careful not to implement new
functionality; the current test should
still fail.
An example
package xpug;
import junit.framework.Assert;

import org.junit.Test;

public class AFizzbuzzer {
	 @Test
	 public void sho...
package xpug;

public class FizzbuzzerFactory {
	 public static Fizzbuzzer create() {
	 	 return new Fizzbuzzer();
	 }
}
package xpug;

public class Fizzbuzzer {
	 public String say(int digit){
	 	 return String.valueOf(digit);
	 }
}
@Test
	   public void shouldReturnFizzForMultipleOfThree(){
	   	 Fizzbuzzer fizzbuzzer = FizzbuzzerFactory.create();
	   ...
package xpug;

public interface Counter {
	 public boolean canHandle(int digit);

	 public String say(int digit);
}
package xpug;

public class Echo implements Counter {

	   @Override
	   public boolean canHandle(int digit) {
	   	 retur...
package xpug;
import java.util.List;

public class Fizzbuzzer {
	 private List<? extends Counter> counters;

	 public Fizz...
package xpug;

import java.util.Arrays;

public class FizzbuzzerFactory {
	 public static Fizzbuzzer create() {
	 	 return...
@Test
	   public void shouldReturnFizzForMultipleOfThree(){
	   	 Fizzbuzzer fizzbuzzer = FizzbuzzerFactory.create();
	   ...
package xpug;
public class Fizz implements Counter {

	   @Override
	   public boolean canHandle(int digit) {
	   	 return...
package xpug;

import java.util.Arrays;

public class FizzbuzzerFactory {
	 public static Fizzbuzzer create() {
	 	 return...
...
...
...
...
...
...
...
package xpug;

import java.util.Arrays;

public class FizzbuzzerFactory {
	 public static Fizzbuzzer create() {
	 	 return...
KataYahtzee
Let’s start!
XpUg Coding Dojo: KataYahtzee in Ocp way
Upcoming SlideShare
Loading in …5
×

XpUg Coding Dojo: KataYahtzee in Ocp way

7,530 views

Published on

Introduction to Ocp way to do a kata, used during a Xpug Milano Coding Dojo.

Published in: Technology, Education
  • I think you need a perfect and 100% unique academic essays papers have a look once this site i hope you will get valuable papers, ⇒ www.HelpWriting.net ⇐
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • If we are speaking about saving time and money this site ⇒ www.WritePaper.info ⇐ is going to be the best option!! I personally used lots of times and remain highly satisfied.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Have you ever used the help of ⇒ www.WritePaper.info ⇐? They can help you with any type of writing - from personal statement to research paper. Due to this service you'll save your time and get an essay without plagiarism.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Have u ever tried external professional writing services like ⇒ www.HelpWriting.net ⇐ ? I did and I am more than satisfied.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating direct: ❶❶❶ http://bit.ly/2u6xbL5 ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

XpUg Coding Dojo: KataYahtzee in Ocp way

  1. Xpug Coding Dojo: The OCP Kata
  2. Kata
  3. Pairs
  4. Randori
  5. Costraints
  6. The OCP Kata http://matteo.vaccari.name/blog/archives/293
  7. 0. Write the first failing test.
  8. Then write a factory that returns an object, or an aggregate of objects, that make the test pass.
  9. The factory should be limited to creating objects and linking them together. No conditionals allowed.
  10. 1. Write the next failing test.
  11. 2. Can you make it pass by changing the factory and/or creating a new class and nothing else?
  12. If yes, great! Go back to 1.
  13. If not, refactor until you can.
  14. 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.
  15. Be careful not to implement new functionality; the current test should still fail.
  16. An example
  17. package xpug; import junit.framework.Assert; import org.junit.Test; public class AFizzbuzzer { @Test public void shouldReturnSameNumberForPlainNumber() { Fizzbuzzer fizzbuzzer = FizzbuzzerFactory.create(); Assert.assertEquals("1", fizzbuzzer.say(1)); Assert.assertEquals("2", fizzbuzzer.say(2)); } }
  18. package xpug; public class FizzbuzzerFactory { public static Fizzbuzzer create() { return new Fizzbuzzer(); } }
  19. package xpug; public class Fizzbuzzer { public String say(int digit){ return String.valueOf(digit); } }
  20. @Test public void shouldReturnFizzForMultipleOfThree(){ Fizzbuzzer fizzbuzzer = FizzbuzzerFactory.create(); Assert.assertEquals("Fizz", fizzbuzzer.say(3)); Assert.assertEquals("Fizz", fizzbuzzer.say(6)); Assert.assertEquals("Fizz", fizzbuzzer.say(9)); }
  21. package xpug; public interface Counter { public boolean canHandle(int digit); public String say(int digit); }
  22. package xpug; public class Echo implements Counter { @Override public boolean canHandle(int digit) { return true; } @Override public String say(int digit) { return String.valueOf(digit); } }
  23. package xpug; import java.util.List; public class Fizzbuzzer { private List<? extends Counter> counters; public Fizzbuzzer(List<? extends Counter> counters) { this.counters = counters; } public String say(int digit) { for (Counter counter : counters) if (counter.canHandle(digit)) return counter.say(digit); return ""; } }
  24. package xpug; import java.util.Arrays; public class FizzbuzzerFactory { public static Fizzbuzzer create() { return new Fizzbuzzer(Arrays.asList( new Echo())); } }
  25. @Test public void shouldReturnFizzForMultipleOfThree(){ Fizzbuzzer fizzbuzzer = FizzbuzzerFactory.create(); Assert.assertEquals("Fizz", fizzbuzzer.say(3)); Assert.assertEquals("Fizz", fizzbuzzer.say(6)); Assert.assertEquals("Fizz", fizzbuzzer.say(9)); }
  26. package xpug; public class Fizz implements Counter { @Override public boolean canHandle(int digit) { return digit % 3 == 0; } @Override public String say(int digit) { return "Fizz"; } }
  27. package xpug; import java.util.Arrays; public class FizzbuzzerFactory { public static Fizzbuzzer create() { return new Fizzbuzzer(Arrays.asList( new Fizz(), new Echo())); } }
  28. ... ... ... ... ... ... ...
  29. package xpug; import java.util.Arrays; public class FizzbuzzerFactory { public static Fizzbuzzer create() { return new Fizzbuzzer(Arrays.asList( new Fizzbuzz(), new Buzz(), new Fizz(), new Echo())); } }
  30. KataYahtzee
  31. Let’s start!

×