Design pattern - Facade Pattern

mudasirqazi00 3,566 views 13 slides Apr 30, 2015
Slide 1
Slide 1 of 13
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13

About This Presentation

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


Slide Content

Façade Pattern From Definition to implementation Mudasir Qazi - [email protected] 1 12-Dec-14

Contents / Agenda Definition Structural Diagrams Advantages and Usage UML – Sequence Diagram Implementation (step 1 to 5) Mudasir Qazi - [email protected] 2 12-Dec-14

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 - [email protected] 3 12-Dec-14

Structural Diagram (1) Mudasir Qazi - [email protected] 4 12-Dec-14

Structural Diagram (2) Mudasir Qazi - [email protected] 5 12-Dec-14

Advantages and Usage Advantages It shields the clients from the complexities of the sub-system components. It promotes loose coupling between subsystems and its clients. Usage When you want to provide simple interface to a complex sub-system. When several dependencies exist between clients and the implementation classes of an abstraction. Login in complex organizations like google, Microsoft’s accounts. Mudasir Qazi - [email protected] 6 12-Dec-14

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 - [email protected] 7 12-Dec-14

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 - [email protected] 8 12-Dec-14

Step 1 Create an interface to enforce common method. In our example it would be Shape interface containing a method draw. Mudasir Qazi - [email protected] 9 12-Dec-14

Step 2 Define concrete classes and implement interface. Mudasir Qazi - [email protected] 10 12-Dec-14

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 - [email protected] 11 12-Dec-14

Step 4 Use Façade class to use sub systems (to draw different shapes). Mudasir Qazi - [email protected] 12 12-Dec-14

Step 5 - output Mudasir Qazi - [email protected] 13 12-Dec-14