Thông tin tài liệu:
Growing Object-Oriented Software, Guided by Tests- P3: Test-Driven Development (TDD) hiện nay là một kỹ thuật được thành lập để cung cấp các phần mềm tốt hơn nhanh hơn. TDD là dựa trên một ý tưởng đơn giản: các bài kiểm tra Viết cho code của bạn trước khi bạn viết đoạn code riêng của mình. Tuy nhiên, điều này "đơn giản" ý tưởng có kỹ năng và bản án để làm tốt. Bây giờ có một tài liệu hướng dẫn thiết thực để TDD mà sẽ đưa bạn vượt ra ngoài những khái niệm cơ bản. Vẽ trên một...
Nội dung trích xuất từ tài liệu:
Growing Object-Oriented Software, Guided by Tests- P376 Chapter 9 Commissioning an Auction Sniper The discussions generate a long list of requirements, such as being able to bid for related groups of items. There’s no way anyone could deliver everything within a useful time, so we talk through the options and the buyers reluctantly agree that they’d rather get a basic application working first. Once that’s in place, we can make it more powerful. It turns out that in the online system there’s an auction for every item, so we decide to use an item’s identifier to refer to its auction. In practice, it also turns out that the Sniper application doesn’t have to concern itself with managing any items we’ve bought, since other systems will handle payment and delivery. We decide to build the Auction Sniper as a Java Swing application. It will run on a desktop and allow the user to bid for multiple items at a time. It will show the identifier, stop price, and the current auction price and status for each item it’s sniping. Buyers will be able to add new items for sniping through the user interface, and the display values will change in response to events arriving from the auction house. The buyers are still working with our usability people, but we’ve agreed a rough version that looks like Figure 9.1. Figure 9.1 A first user interface This is obviously incomplete and not pretty, but it’s close enough to get us started. While these discussions are taking place, we also talk to the technicians at Southabee’s who support their online services. They send us a document that To Begin at the Beginning 77describes their protocol for bidding in auctions, which uses XMPP (Jabber) forits underlying communication layer. Figure 9.2 shows how it handles multiplebidders sending bids over XMPP to the auction house, our Sniper being one ofthem. As the auction progresses, Southabee’s will send events to all the connectedbidders to tell them when anyone’s bid has raised the current price and when theauction closes. Figure 9.2 Southabee’s online auction system XMPP: the eXtensible Messaging and Presence Protocol XMPP is a protocol for streaming XML elements across the network. It was origi- nally designed for, and named after, the Jabber instant messaging system and was renamed to XMPP when submitted to the IETF for approval as an Internet standard. Because it is a generic framework for exchanging XML elements across the network, it can be used for a wide variety of applications that need to exchange structured data in close to real time. XMPP has a decentralized, client/server architecture. There is no central server, in contrast with other chat services such as AOL Instant Messenger or MSN Messenger. Anyone may run an XMPP server that hosts users and lets them communicate among themselves and with users hosted by other XMPP servers on the network. A user can log in to an XMPP server simultaneously from multiple devices or clients, known in XMPP terminology as resources. A user assigns each resource a priority. Unless addressed to a specific resource, messages sent to the user are delivered to this user’s highest priority resource that is currently logged in. Every user on the network has a unique Jabber ID (usually abbreviated as JID) that is rather like an e-mail address. A JID contains a username and a DNS address of the server where that user resides, separated by an at sign (@, for example, username@example.com), and can optionally be suffixed with a resource name after a forward slash (for example, username@example.com/office).78 Chapter 9 Commissioning an Auction Sniper Communicating with an Auction The Auction Protocol The protocol for messages between a bidder and an auction house is simple. Bidders send commands, which can be: Join A bidder joins an auction. The sender of the XMPP message identifies the bidder, and the name of the chat session identifies the item. Bid A bidder sends a bidding price to the auction. Auctions send events, which can be: Price An auction reports the currently accepted price. This event also includes the minimum increment that the next bid must be raised by, and the name of bidder who bid this price. The auction will send this event to a bidder when it joins and to all bidders whenever a new bid has been accepted. Close An auction announces that it has closed. The winner of the last price event has won the auction. Figure 9.3 A bidder’s behavior represented as a state machine ...