design pattern - facade pattern
TRANSCRIPT
Mudasir Qazi - [email protected] 2
Contents / Agenda
• Definition• Structural Diagrams• Advantages and Usage• UML – Sequence Diagram• Implementation (step 1 to 5)
12-Dec-14
Mudasir Qazi - [email protected] 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.12-Dec-14
Mudasir Qazi - [email protected] 6
Advantages and Usage
• Advantages1. It shields the clients from the complexities of the sub-system components.2. It promotes loose coupling between subsystems and its clients.
• Usage1. 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.
12-Dec-14
Mudasir Qazi - [email protected] 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.
12-Dec-14
Mudasir Qazi - [email protected] 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.
12-Dec-14
Mudasir Qazi - [email protected] 9
Step 1
• Create an interface to enforce common method.In our example it would be Shape interface containing a method draw.
12-Dec-14
Mudasir Qazi - [email protected] 10
Step 2
• Define concrete classes and implement interface.
12-Dec-14
Mudasir Qazi - [email protected] 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.
12-Dec-14
Mudasir Qazi - [email protected] 12
Step 4
• Use Façade class to use sub systems (to draw different shapes).
12-Dec-14