This is a series of blog posts going through the great book Growing Object Oriented Software Guided By Tests, typing in code chapter by chapter, trying to add some of my own understanding where things may not be easy to grasp in the book. I highly recommand you get a copy of the book and follow along with me. Happy coding.
This post is the beginning of Chapter 15 Towards a Real User Interface.
We decided to replace the simple label with a table to represent snipers. To play it safe, we make a baby step: create a one cell table to just replace the text label.
Sending the State out of the Sniper
In the new
JTable, we show 3 columns:
lastBid. Since these 3 values aways go together, we can bundle them up into a
AuctionSniper is a listener in
AuctionMessageTranslator. When there is a PRICE message coming, the
currentPrice(int price, int increment, PriceSource priceSource) will be called.
lastPrice can be taken directly from
lastBid can be calculated by
price + increment, what about the
itemId? We decided to put it in the
AuctionSniper’s constructor, since
Main knows which item we are bidding, we can pass it to create the
AuctionSniper. Also we change the tests.
Showing a Bidding Sniper
In order to show the
SniperState on UI, we pass it to the
SnipersTableModel and use it to show in the table. Nothing really interesting here.