0% found this document useful (0 votes)
7 views21 pages

06 Facade

Uploaded by

mirabeymi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views21 pages

06 Facade

Uploaded by

mirabeymi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Facade Pattern

A structural design pattern that provides a simplified


interface to a library, a framework, or any other complex
set of classes.

1
2
Facade Pattern

3
Watching a movie (the hard way)

4
Home Theater

A lot of classes, a lot


of interactions, and a
big set of interfaces to
learn and use

5
Tasks in terms and
the method calls needed to perform them

6
The Facade simplifies this system
Client code now calls methods
on the home theater Facade

7
Facades and adapters may wrap multiple classes, but a
facade’s intent is to simplify, while an adapter’s is to
convert the interface to something different.

8
Constructing your home theater facade

9
Implementing the simplified interface

10
Time to watch a movie (the easy way)

11
Time to watch a movie (the easy way)

12
Facade Pattern UML Class diagram

13
The Facade and the Principle of Least Knowledge

14
Hiding the complexities of the system and providing an interface to the
client from where the client can access the system. 15
The hotel has a hotel keeper.
There are Veg, Non-Veg and Veg/Non Both restaurants.
A client wants to access to different menus of different restaurants .
You do not know what are the different menus they have.
You just have access to hotel keeper who knows his hotel well.
Whichever menu you want, you tell the hotel keeper and he gives it to you.
The hotel keeper acts as the facade, as he hides the complexities of the
system hotel.

16
17
18
19
In this way the implementation is sent to the facade.
The client is given just one interface and can access only that.
This will hide all complexities.
Pros
• You can isolate your code from the complexity of
subsystems.
Cons
• A facade can become a god object coupled to all classes
of an app.

21

You might also like