• Save
Bowling: An emergent design case study (C# version)
Upcoming SlideShare
Loading in...5
×
 

Bowling: An emergent design case study (C# version)

on

  • 1,525 views

Another implementation of the Bowling Kata, this time in C#, showing a different design premise and how it evolved. ...

Another implementation of the Bowling Kata, this time in C#, showing a different design premise and how it evolved.

You can find the code here: https://github.com/fcuenca/CsharpPlayground/commits/master/CsharpKatas/trunk/CsharpKatas/BowlingKata/BowlingTests.cs

by Fernando Cuenca, Agile Coach
fcuenca@teksystems.com

blog: http://opinionateddevelopment.blogspot.ca/
twitter: @fer_cuenca

Statistics

Views

Total Views
1,525
Slideshare-icon Views on SlideShare
1,525
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

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
  • Initial design ideas: The Game has a collection of Frames. When asked to produce a score, the Game will traverse the collection of Frames delegating the actual calculation to a Score object
  • Very simple initial design with a single class. Rolls kept as integers in an array. Score calculated as the sum of those numbers.
  • Dealing with Strikes and Spares introduces the need for a Frame objectDealing with incomplete frames introduces logic in the Game class to “try” to build frames as rolls come along.The Game class now has also another distinct responsibility: building frames at the appropriate time => this suggests a new class is needed
  • Creation of the Frames is refactored into a new class: FrameFactory.But this class needs to know too much about “well formed” frames.
  • Now the Factory is responsible for the logic of when to “release” complete frames to the game, but the inner details of how frames work are the responsibility of the Frame class.
  • Lots of conditional logicCombinatorial explosion of cases makes difficult to choose which tests to work on, and will lead to even more conditional logicPlenty of duplication already (within the function, and with other code in the Frame class)The design so far seems to work, and we can see how it will support the stories that are coming next, but the direction it’s going will result in even more complexity and conditional logic. But at this point we know a lot about the nature of the problem; thinking about what we’ve done so far, where do we need to go and how we got here, leads to a breakthrough.
  • The new algorithm it’s based on a different concept: keeping frames that are “pending” (because they can’t be scored yet), and “consuming” rolls once they become available.It (supposedly) handles all the combinations of strikes, spares and strikes (although it hasn’t been proved yet)It still has quite a bit of conditional logic and duplication, but now it’s clear how to clean it up. (see following steps.)
  • We’re not done yet!
  • Fortunately, the new requirement just fits nicely in the existing framework.

Bowling: An emergent design case study (C# version) Bowling: An emergent design case study (C# version) Presentation Transcript

  • Scoring BowlingAn Emergent Design Case Study (II)
  • Fernando A. CuencaAgile Coachfcuenca@teksystems.comhttp://opinionateddevelopment.blogspot.ca@fer_cuencaBlogTwitterAbout me
  • Slide 3Scoring Bowling: The RulesThe game consists of 10 frames as shown above. In each frame the player hastwo opportunities to knock down 10 pins. The score for the frame is the totalnumber of pins knocked down, plus bonuses for strikes and spares.A spare is when the player knocks down all 10 pins in two tries. The bonus forthat frame is the number of pins knocked down by the next roll. So in frame 3above, the score is 10 (the total number knocked down) plus a bonus of 5 (thenumber of pins knocked down on the next roll.)A strike is when the player knocks down all 10 pins on his first try. The bonusfor that frame is the value of the next two balls rolled.In the tenth frame a player who rolls a spare or strike is allowed to roll the extraballs to complete the frame. However no more than three balls can be rolled intenth frame.From the original “Bowling Kata”, by Robert “Uncle Bob” Martinhttp://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata
  • Slide 4Epics & Initial Design idea Open Frames are scored by adding the number of pins knocked down in two rolls Spares have score of 10 plus a bonus equal to the number of pins knocked down in the next roll Strikes have a score of 10 plus a bonus equal to the number of pins knocked down in the next two rolls The last frame is allowed to have additional rolls to complete the scoring (up to 3 rolls.)
  • Slide 5Steps 1 – 2 Stories: Game starts with a Score of zero Game score accumulated as balls are rolled Incomplete rolls not scored just yet
  • Slide 6Steps 3 – 6 Stories: Scoring a Spare uses next roll a bonus Incomplete Spares not scored just yet Scoring a Strike uses the next two rolls as bonus Incomplete Strikes not scored just yet
  • Slide 7Step 7
  • Slide 8Steps 8 – 11
  • Slide 9Steps 12 – 13 Stories: Multiple Spares in a Row Strikes mixed with Spares Multiple Strikes in a Row
  • Slide 10The implementation turns ugly…
  • Slide 11Whiteboarding a new solution …… substituting the implementation…(Step 14)
  • Slide 12… then cleaning it up by moving responsibilities around
  • Slide 13But… oops!The last frame is allowed to have additionalrolls to complete the scoring (up to 3 rolls.)
  • Slide 14Step 23
  • Slide 15From original concept to final design