Facade Design Pattern Flashcards

1
Q

Facade Design Pattern

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the Facade Pattern?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What problems does the Facade Pattern address?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the main solution offered by the Facade Pattern?

A

Create a Facade class that provides a simple interface to the complex subsystem

The Facade encapsulates complexity and provides only necessary features to clients.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a real-world analogy for the Facade Pattern?

A

Placing a phone order

The operator acts as a Facade, providing a simple interface to the ordering system, payment gateways, and delivery services.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the components of the Facade Pattern structure?

A

The structure includes:
* Facade
* Complex Subsystem
* Client

The Facade provides a simple interface, while the complex subsystem consists of many interacting classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the role of the Facade in the Facade Pattern?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When should you use the Facade Pattern?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the pros of the Facade Pattern?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the cons of the Facade Pattern?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How does the Facade Pattern relate to the Adapter Pattern?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the difference between the Facade Pattern and the Mediator Pattern?

A

Facade provides a simplified interface to a subsystem, while Mediator centralizes communication between components

Both organize collaboration between tightly coupled classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Fill in the blank: The Facade Pattern promotes _______.

A

loose coupling

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a key takeaway of the Facade Pattern?

A

It provides a simple interface to a complex subsystem and improves maintainability

Use it to hide complexity and provide a user-friendly interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the purpose of the Facade class in the provided pseudocode example?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

True or False: The Facade Pattern can help in reducing boilerplate code.

17
Q

What should you do if the Facade becomes too large?

A

Extract part of its behavior into a new Facade

This helps maintain simplicity and manageability.

18
Q

What kind of code example can demonstrate the Facade Pattern?

A

A code example that shows a simple interface for video conversion

Such as using a VideoConverter class to handle complex video processing tasks.