GOOS Book Distilled Part 6

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

稿源:Guowei Lv (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 综合编程 » GOOS Book Distilled Part 6

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录