Problem Set: 2 1. How do you detach responsibilities in Decorator? 2. How do you dynamically switch between algorithms in the strategy pattern. What additional infrastructure do you need for this. 3. Clearly understand the reason why a "bridge" pattern is used for implementing portability across windowing standards rather than an "abstract factory" pattern. 4. A combinatorial auction is one where a seller announces the availability of a package of products for selling and prospective buyers bid for bundles (or subsets of these products). An auction object can be either a simple auction object (where only one product type is involved) or a combinatorial auction type. Once the type of the auction object type is fixed, the structure of bids and offers should conform to that auction type. Show a class diagram which can capture the main classes in such an application using design patterns. 5. In the above problem, the winner determination (algorithm to decide who the winners are) depends on the type of auction. Also, for a given auction type, there could be several different ways in which winners could be determined. Furthermore, once the winners are determined, the prices they pay could be determined in a variety of ways. Use design pattern(s) to show these details could be captured in an extensible way. 6. Let us say you are using the composite pattern to represent assets of an individual. An asset could be a one or more bank accounts, one or more stocks, one or more properties, or any bundling of these. Write down a class diagram depicting this. 7. An electronic document is to be tranferred from one machine to another using the web. Depending on the nature of the document, it is automatically decided (a) whether the document should be sent in compressed form or in original (uncompressed) form; (b) whether the document should be sent in secure mode or insecure mode. The decision about compression or security is made dynamically only after looking at the header of the document. Decide whether you want to use strategy or decorator here and set up a class diagram representing all essential abstractions. 8. A bank allows its account holders to open deposits through a secure online system. There are three different types of deposits that customers may open: fixed deposits, recurring deposits, mixed deposits. (a) What would be a good creational pattern to use to generate the relevant form on-line. Explain your answer. (b) If innovative new types of deposits have to be introduced by the bank in future, which design pattern will help you to maximize reuse of client code. Explain your answer. 9. A trading application is used in three modes: (a) "forward auction" mode where there is one seller and multiple buyers (b) "reverse auction" mode in which there is one buyer and multiple sellers (c) a "double auction" mode where there are multiple sellers and multiple buyers. Several trading applications may have to be deployed concurrently by the trading server. Write down three "compelling" design patterns which may be used in designing this trading application, so as to maximize reuse. Justify your answer in each case. 10. In the auction house case study, explain how the following patterns will be useful: (a) COR (b) Mediator (c) Command (d) Proxy (e) Iterator