Exam 2 - L15 - Adapter Design Pattern Flashcards

1
Q

What type of design pattern is the Adapter Pattern

A

A structural design pattern.

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

What is the purpose of the Adapter Pattern?

A

To allow objects with incompatible interfaces to collaborate by wrapping one object to adapt its interface to another.

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

What is another name for the Adapter Pattern?

A

The Wrapper Pattern.

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

When might you use an Adapter instead of modifying a class directly?

A

When you don’t have access to the source code
or
When modifying it would break existing functionality that relies on its current interface.

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

How does an adapter work internally?

A

The adapter wraps an object, intercepts method calls, translates or converts data, and forwards the request to the target object in a compatible format.

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

Can an adapter be bidirectional?

A

Yes, in some cases, two-way adapters can be created to handle conversions in both directions.

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

How does the Adapter Pattern follow the Single Responsibility Principle?

A

It separates the concern of data / interface conversion from the core business logic.

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

How does the Adapter Pattern follow the Open/Closed Principle?

A

You can add new adapters for new data formats or libraries without changing the existing client code.

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

What is the downside of using the Adapter Pattern?

A

It increases overall code complexity by introducing more interfaces and classes.

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

What does it mean that the Adapter Pattern is a structural pattern?

A

Patterns that focus on how classes and objects are composed - - - Helping ensure that components work together despite incompatible interfaces.

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

What is meant by incompatible interfaces?

A

Two classes or systems have methods or data formats that don’t match, preventing direct collaboration unless an intermediary (like an adapter) is used.

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

What is interface conversion?

A

Changing how one class presents its methods or data so that it matches what another class expects.

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

What is the role of a wrapper in the Adapter Pattern?

A

The wrapper (adapter) encapsulates an existing object and translates method calls and data formats to match a new interface.

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

Why is modifying a third-party library often avoided?

A

You may not have access to its source code, or changing it could break compatibility with other parts of the system.

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

How is an adapter created in code?

A

By implementing a target interface expected by the client and wrapping an instance of the incompatible class, translating method calls and data.

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

What does a one-way adapter do?

A

It only translates calls in one direction, from the client to the adaptee.

17
Q

What is a two-way adapter?

A

An adapter that can translate calls in both directions, allowing full communication between two incompatible interfaces.

18
Q

What is the ‘client’ in the Adapter Pattern context?

A

The class or system that wants to use another class but cannot because of interface mismatch.

19
Q

What is the ‘adaptee’ in the Adapter Pattern?

A

The existing class or object whose interface is incompatible with the client.

20
Q

What principle helps adapters make a system extensible without modifying existing code?

A

The Open/Closed Principle.

Classes should be open for extension but closed for modification.

21
Q

What specific benefit does the Adapter Pattern offer to legacy system integration?

A

It enables modern systems to interact with outdated components by adapting their interfaces instead of rewriting code.

22
Q

What is a real world analogy for the Adapter Pattern?

A

A power plug adapter that lets a U.S. plug work in a European socket by translating physical and electrical formats.