More Related Content
Similar to Design Patterns - 04 Adapter and Facade Pattern (20)
Design Patterns - 04 Adapter and Facade Pattern
- 1. 04 Adapter and Façade Pattern Design Patterns © Prafulla Paraskar 2010
- 3. Definition The adapter pattern (often referred to as the wrapper pattern or simply a wrapper) is a design pattern that translates one interface for a class into a compatible interface. (wikipedia) © Prafulla Paraskar 2010
- 5. Adapter Pattern – Explained (2/2) An adapter allows classes to work together that normally could not because of incompatible interfaces, by providing its interface to clients while using the original interface. The adapter translates calls to its interface into calls to the original interface, and the amount of code necessary to do this is typically small. The adapter is also responsible for transforming data into appropriate forms. © Prafulla Paraskar 2010
- 6. Adapter Pattern – Types of Adapters Class adapter Simple and versatile, invisible to the client. Object adapter Extensible to subclasses of the adapter. Two-way adapter Enables different clients to view an object differently. Pluggable adapter Presence of adapter is transparent; it can be put in and taken out. Several adapter can be active. © Prafulla Paraskar 2010
- 8. Adapter Pattern – Real World Samples AC adaptors Car charger for mobile phones COM InterOp in .NET SQLAdapter in .NET © Prafulla Paraskar 2010
- 9. Adapter Pattern – Guidelines You have : A domain specific interface. A Class to connect to with a mismatching interface. You Want : Create a reusable class to cooperate with yet-to-be-built classes. Change the names of methods as called and as implemented. Support different sets of methods for different purposes. © Prafulla Paraskar 2010
- 11. Definition A facade is an object that provides a simplified interface to a larger body of code, such as a class library (wikipedia). © Prafulla Paraskar 2010
- 13. Façade Pattern – Explained (2/2) The name is by analogy to an architectural facade. A facade can: make a software library easier to use and understand and test, since the facade has convenient methods for common tasks. make code that uses the library more readable, for the same reason. reduce dependencies of outside code on the inner workings of a library, since most code uses the facade, thus allowing more flexibility in developing the system. wrap a poorly-designed collection of APIs with a single well-designed API (as per task needs). © Prafulla Paraskar 2010
- 14. Façade Pattern – Types of Adapters Opaque Subsystem operations can only be called through the Façade. Transparent Subsystem operations can be called directly as well as through the Façade. Singleton Only one instance of the Façade is meaningful. © Prafulla Paraskar 2010
- 16. Façade Pattern – Real World Samples Wedding planners / Event management. DirectX / OpenGL Online bill payment Macros in MS Office © Prafulla Paraskar 2010
- 17. Façade Pattern – Guidelines When: A system has several identifiable subsystems and: The abstractions and implementations of a subsystem are tightly coupled. The system evolves and gets more complex, but early adapters might want to retain their simple views. You want to provide alternative novice, intermediate and power user interfaces. There is a need for an entry point to each level of layered software. © Prafulla Paraskar 2010