Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Design pattern - Facade Pattern


Published on

in these slides i have explained the Facade design pattern. slides includes definition, explanation and then implementation by code examples.

Published in: Engineering
  • Be the first to comment

Design pattern - Facade Pattern

  1. 1. Façade Pattern From Definition to implementation Mudasir Qazi - 112-Dec-14
  2. 2. Contents / Agenda • Definition • Structural Diagrams • Advantages and Usage • UML – Sequence Diagram • Implementation (step 1 to 5) Mudasir Qazi - 212-Dec-14
  3. 3. Definition • A Facade Pattern says that just "just provide a unified and simplified interface to a set of interfaces in a subsystem, therefore it hides the complexities of the subsystem from the client". • In other words, Facade Pattern describes a higher-level interface that makes the sub-system easier to use. • Practically, every Abstract Factory is a type of Facade. • This pattern involves a single class which provides simplified methods which are required by client and delegates calls to existing system classes methods. • It comes under “Structural Design Patterns” category. Mudasir Qazi - 312-Dec-14
  4. 4. Structural Diagram (1) Mudasir Qazi - 412-Dec-14
  5. 5. Structural Diagram (2) Mudasir Qazi - 512-Dec-14
  6. 6. Advantages and Usage • Advantages 1. It shields the clients from the complexities of the sub-system components. 2. It promotes loose coupling between subsystems and its clients. • Usage 1. When you want to provide simple interface to a complex sub-system. 2. When several dependencies exist between clients and the implementation classes of an abstraction. 3. Login in complex organizations like google, Microsoft’s accounts. Mudasir Qazi - 612-Dec-14
  7. 7. UML – Sequence Diagram Note the differences between ‘Before’ and ‘after’ event sequence. In first case, each time client need to interact with System it has to interact with 3 separate sub systems. In Second case, client just interact with Façade and it manages all internal affairs. Mudasir Qazi - 712-Dec-14
  8. 8. Implementation (C# and Java) • We are going to implement following system class diagram. Each time we need to create a ‘Shape’, we just interact with ShapeMaker (Façade) and it will manage the internal complexities. Mudasir Qazi - 812-Dec-14
  9. 9. Step 1 • Create an interface to enforce common method. In our example it would be Shape interface containing a method draw. Mudasir Qazi - 912-Dec-14
  10. 10. Step 2 • Define concrete classes and implement interface. Mudasir Qazi - 1012-Dec-14
  11. 11. Step 3 Façade class acts as a wrapper class which contains all sub systems. In our example it will contain Circle, Rectangle and Square type of objects. Then you can have different necessary methods. Mudasir Qazi - 1112-Dec-14
  12. 12. Step 4 • Use Façade class to use sub systems (to draw different shapes). Mudasir Qazi - 1212-Dec-14
  13. 13. Step 5 - output Mudasir Qazi - 1312-Dec-14