Jason and I went through the slides discussing OO design as we went. After
looking at the user cases, acceptance tests and CRC cards, we started writing an
implementation of the software.
Tests
This is as far as we got:
add a new title
donating a copy of a title that isn’t in the library add the title to the
library
donating a copy of a different title that isn’t in the library adds the title
to the library
finding a title that doesn’t exist in the library returns null.
To satisfy 1 we mocked the title class and wrote a method addToNewTitles on
library to add that title to library. The assertion used a getNewTitles method
that returned a list of new titles. Initially we tried using arrays but lists
have a nicer set of methods such as contains that saved us the cost of writing
sorting and searching algorithms (that would also require us to implement quite
a bit of title). Satisfying 2 involved adding a title to the library, and then
returning the first element of the list holding our titles. The assertions we
were writing to check the title was correct were very horrible, lots of getters
on title–poor emergent design. Next week we’ll have a look at how to go from
our current implementation to something a little cleaner doing lots of
refactoring!
LibraryTests.java
Library.java
Title.java
The Homework: User stories, Acceptance tests, and CRC cards for an interesting problem
Jason wants me to have ago applying the principles that we covered in the
pairing session on a different example, so I have free reign over what I want to
do. I’m quite interested in writing an app that allows users to track how often
they indulge in their vices. In my case: alcohol, I’d like to cut down on my
consumption, but I’m not quite sure how much I’m drinking, having an app to
record this information would be very helpful. Graphing it would be even more
helpful to see whether I’m decreasing my intake or not.