GOOS Book Distilled Part 6

A follow through of the great book Growing Object-Oriented Software, Guided by Tests with code

2 minute read

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 is the beginning of Chapter 13 in the book.

Well, we have a problem about Main.

Let’s see what Main is currently doing for us.

  1. It handles UI work.
  2. It handles connection to XMPP server.
  3. It implements AuctionEventListener. That is AuctionMessageTranslator uses it as a listener.

Among the 3 resposibilities, the 3rd one feels not quite right. As the types of messages grows, Main will have to do more and more stuff.

Now it is time to create a AuctionSniper class to make Main’s life easier. Now thinking about it, it is quite weird that there is no class named after sniper since our application is call auction sniper. Let’s also create a SniperListener to put into AuctionSniper, so that AuctionSniper does not directly depend on UI.

Now the architecture looks like this:

Pay attention to this structure, something interesting is happening. The shaded components(Chat and Main) have been pushed to the sides. And what in the middle forms the core of our business logic of the app.

Source code

comments powered by Disqus