Facade Design Pattern Flashcards
Facade Design Pattern
What is the Facade Pattern?
A structural design pattern that provides a simplified interface to a complex set of classes
It hides the complexity of the subsystem and provides an easy-to-use interface for the client.
What problems does the Facade Pattern address?
It addresses issues related to:
* Initializing many objects
* Managing dependencies
* Executing methods in the correct order
These issues can lead to tight coupling between business logic and subsystem details.
What is the main solution offered by the Facade Pattern?
Create a Facade class that provides a simple interface to the complex subsystem
The Facade encapsulates complexity and provides only necessary features to clients.
What is a real-world analogy for the Facade Pattern?
Placing a phone order
The operator acts as a Facade, providing a simple interface to the ordering system, payment gateways, and delivery services.
What are the components of the Facade Pattern structure?
The structure includes:
* Facade
* Complex Subsystem
* Client
The Facade provides a simple interface, while the complex subsystem consists of many interacting classes.
What is the role of the Facade in the Facade Pattern?
The Facade provides a simple interface, directs client requests, and operates the subsystem
It knows how to manage interactions between the client and the subsystem.
When should you use the Facade Pattern?
Use it when:
* You need a simple interface to a complex subsystem
* Subsystems become more complex over time
* You want to structure a subsystem into layers
This helps reduce boilerplate code and coupling.
What are the pros of the Facade Pattern?
Pros include:
* Isolates complexity
* Improves maintainability
* Promotes loose coupling
Clients do not need to understand the subsystem, and changes to it do not affect clients.
What are the cons of the Facade Pattern?
Cons include:
* Risk of god object
* Limited functionality
The Facade can become overly complex if it tries to do too much, and it may not expose all features of the subsystem.
How does the Facade Pattern relate to the Adapter Pattern?
Facade defines a new interface for existing objects, while Adapter makes an existing interface usable
Adapter usually wraps one object, while Facade works with an entire subsystem.
What is the difference between the Facade Pattern and the Mediator Pattern?
Facade provides a simplified interface to a subsystem, while Mediator centralizes communication between components
Both organize collaboration between tightly coupled classes.
Fill in the blank: The Facade Pattern promotes _______.
loose coupling
What is a key takeaway of the Facade Pattern?
It provides a simple interface to a complex subsystem and improves maintainability
Use it to hide complexity and provide a user-friendly interface.
What is the purpose of the Facade class in the provided pseudocode example?
To encapsulate the complexity of video conversion and provide a simple method for clients to use
It allows clients to convert videos without dealing with the underlying complexities.
True or False: The Facade Pattern can help in reducing boilerplate code.
True
What should you do if the Facade becomes too large?
Extract part of its behavior into a new Facade
This helps maintain simplicity and manageability.
What kind of code example can demonstrate the Facade Pattern?
A code example that shows a simple interface for video conversion
Such as using a VideoConverter class to handle complex video processing tasks.