GOOS Book Distilled Part 6
A follow through of the great book Growing Object-Oriented Software, Guided by Tests with code
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.
- It handles UI work.
- It handles connection to XMPP server.
- It implements
AuctionEventListener
. That isAuctionMessageTranslator
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.
Share this post
Twitter
Google+
Facebook
Reddit
LinkedIn
StumbleUpon
Email