tailieunhanh - Growing Object-Oriented Software, Guided by Tests- P4

Growing Object-Oriented Software, Guided by Tests- P4: 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. | Chapter 13 The Sniper Makes a Bid developers shouldn t be shy about creating new types. We think Main still does too much but we re not yet sure how best to break it up. We decide to push on and see where the code takes us. Sending a Bid An Auction Interface The next step is to have the Sniper send a bid to the auction so who should the Sniper talk to Extending the SniperListener feels wrong because that relationship is about tracking what s happening in the Sniper not about making external commitments. In the terms defined in Object Peer Stereotypes page 52 SniperListener is a notification not a dependency. After the usual discussion we decide to introduce a new collaborator an Auction. Auction and SniperListener represent two different domains in the application Auction is about financial transactions it accepts bids for items in the market and SniperListener is about feedback to the application it reports changes to the current state of the Sniper. The Auction is a dependency for a Sniper cannot function without one whereas the SniperListener as we discussed above is not. Introducing the new interface makes the design look like Figure . Figure Introducing Auction The AuctionSniper Bids Now we re ready to start bidding. The first step is to implement the response to a Price event so we start by adding a new unit test for the AuctionSniper. It says that the Sniper when it receives a Price update sends an incremented bid to the auction. It also notifies its listener that it s now bidding so we add a sniperBidding method. We re making an implicit assumption that the Auction knows which bidder the Sniper represents so the Sniper does not have to pass in that information with the bid. Sending a Bid public class AuctionSniperTest private final Auction auction private final AuctionSniper sniper new AuctionSniper auction sniperListener @Test public void bidsHigherAndReportsBiddingWhenNewPriceArrives final int price 1001 final int .

TỪ KHÓA LIÊN QUAN