Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Are the four XP rules of Simple Design part of ...

Are the four XP rules of Simple Design part of TDD?

Download for perfect quality. Are the four XP rules of Simple Design part of TDD?

Philip Schwarz

July 20, 2019
Tweet

More Decks by Philip Schwarz

Other Decks in Programming

Transcript

  1. 1.Start with a test, so we will know when we

    are done. We have to do a certain amount of design just to write the test: What are the objects and their visible methods? 2.Design and implement just enough to get that test running. You will have to design enough of the implementation to get this test and all previous tests running. 3.Repeat. 4.If you ever see the chance to make the design simpler, do it. See the subsection ‘What Is Simplest’? for a definition of the principles that drive this. The XP Design Strategy: REFACTOR step XP’s 4 Rules of Simple Design The TDD cycle is as follows. 1. Add a little test. 2. Run all tests and fail. 3. Make a change. 4. Run the tests and succeed. 5. Refactor to remove duplication. What Is Simplest? …the best design is the simplest design that runs all the test cases…Here is what I mean by simplest—four constraints, in priority order: 1. The system (code and tests together) must communicate everything you want to communicate. 2. The system must contain no duplicate code. (1 and 2 together constitute the Once and Only Once rule). 3. The system should have the fewest possible classes. 4. The system should have the fewest possible methods. Kent Beck 1 2 3 4 …That's the whole XP development cycle. Notice that: • Pairs of programmers program together. • Development is driven by tests. You test first, then code. Until all the tests run, you aren't done. When all the tests run, and you can't think of any more tests that would break, you are done adding functionality. • Pairs don't just make test cases run. They also evolve the design of the system…. @philip_schwarz Are XP’s four rules of simple design part of TDD? I reckon so, because I see a direct correspondence between the XP Design Strategy and the TDD RED-GREEN-REFACTOR cycle. Remember, our cycle has different phases (they go by quickly, often in seconds, but they are phases.): 1. Write a test. 2. Make it compile. 3. Run it to see that it fails. 4. Make it run. 5. Remove duplication. XP’s Simple Design The right design for the software at any given time is the one that 1.Runs all the tests. 2.Has no duplicated logic. Be wary of hidden duplication . like parallel class hierarchies. 3.States every intention important to the programmers. 4.Has the fewest possible classes and methods. TDD RED-GREEN-REFACTOR cycle