tailieunhanh - Interface-Oriented Design phần 10
Bạn có thể tìm thấy commonness trong hầu như bất cứ điều gì. Ví dụ, "Tại sao là một bóng đèn như Doonesbury?" Không ai có thể huýt sáo. Chúng ta sẽ nhìn vào giao diện cho một máy in để chứng minh một loạt các sự cố kết. Tùy thuộc vào quan điểm của bạn, bạn có thể xem xét rằng tất cả các hoạt động máy in thuộc trong một giao diện | Things to Remember 186 Alternatively we could have an implementation that connects to multiple sources. It could average the prices from all sources or it could call each source in turn until it found one that responded. The user s code would look the same except for setting up the StockTickerQuoter-Container interface StockTickerQuoterContainer add StockTickerQuoter remove StockTickerQuoter class StockTickerQuoterMultiple implements StockTickerQuoter StockTickerQuoterContainer A factory method can make using a composite like this transparent. Inside the method StockTickerQuoter implementations can be added to StockTickerQuoterContainer. We might obtain an implementation with this enumeration StockTickerQuoterType FREE_BUT_DELAYED_SINGLE_SOURCE PRICEY_BUT_CURRENT_SINGLE_SOURCE AVERAGE_ALL_SOURCES StockTickerQuoter stock_ticker_quoter AVERAGE_ALL_SOURCES Composite Advantage calls to multiple implementations appear the same as calls to a single implementation Things to Remember We ve looked at a number of patterns that deal with interfaces. These patterns are ways that multiple interfaces or multiple implementations can be opaque to the user. Employing these patterns can make your code more flexible and potentially easier to test. Factory Method Proxy Adapter Decorator Faẹade Composite Appendix You may be reading this because you didn t see the title Appendix. Why is this material in an appendix Well it s an accessory structure of the body of the book. Some people might find particular topics in here that they think should have been part of the regular text. Just because the topics are in here doesn t mean they are not important they just didn t fit into the flow. So they got relegated to More about Document Style We discussed document-style interfaces in Chapter 6. Here are a few more suggestions on how to employ them. Document Suggestions The XML Design ASC X12C .
đang nạp các trang xem trước