Adapter Pattern - Geese to Ducks
Description:
Task
Given an interface IDuck
, you are to create an Object Adapter (using Composition) in order to adapt the Goose
class to support the IDuck
interface.
IDuck Interface
public interface IDuck
{
string Quack();
void Fly();
}
Goose Class
public class Goose
{
string Honk();
void Fly();
}
Adapter Pattern
The adapter pattern converts the interface of one class into the interface of another that the client expects. Adapters allow one class to work in an instance where it otherwise couldn't because of incompatible interfaces.
The adapter structure uses either composition (object adapters) or inheritance (class adapters, used in languages that support multiple inheritance) to provide the expected interface that the client relies on. The participants of the pattern involve the following:
- [Target] - Defines the domain-specific interface that the [Client] will use.
- [Client] - Collaborates with the objects conforming to the [Target] interface.
- [Adaptee] - Defines an existing interface that needs adapting.
- [Adapter] - Adapts the interface of the [Adaptee] to the [Target] interface.
Adapter UML
![``` [ Client ] ═══► [ Target ] [ Adaptee ] Request() SepcificRequest() ▲ ▲ ╚═════ [ Adapter ] ═════════════╝ Request() adaptee | └-----------------------► adaptee->SpecificRequest()
```](http://oi66.tinypic.com/2ajb70g.jpg)
For more information on the Adapter Pattern, see:
Similar Kata:
Stats:
Created | Jul 23, 2016 |
Published | Jul 23, 2016 |
Warriors Trained | 1070 |
Total Skips | 78 |
Total Code Submissions | 2161 |
Total Times Completed | 587 |
C# Completions | 380 |
C++ Completions | 218 |
Total Stars | 23 |
% of votes with a positive feedback rating | 85% of 106 |
Total "Very Satisfied" Votes | 78 |
Total "Somewhat Satisfied" Votes | 24 |
Total "Not Satisfied" Votes | 4 |
Total Rank Assessments | 8 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 8 kyu |