Reputation: 4053
I'm just wondering how to use Adapter pattern with more adaptees?
class MainApp
{
static void Main()
{
Target target = new Adapter();
target.Request();
Console.ReadKey();
}
}
class Target
{
public virtual void Request()
{
Console.WriteLine("Called Target Request()");
}
}
class Adapter : Target
{
private Adaptee _adaptee = new Adaptee();
public override void Request()
{
_adaptee.SpecificRequest();
}
}
class Adaptee
{
public void SpecificRequest()
{
Console.WriteLine("Called SpecificRequest()");
}
}
As you can see in this case we have only one adaptee, but I'm not sure how to use the pattern if we have more than one adaptee that don't have any similarities.
Thank you anyone who can suggest something.
Upvotes: 0
Views: 267
Reputation: 9283
Adapter adapts some adaptee to given interface. So if you want to share one adapter with more adaptees it makes sense only when they share the same interface. So you allways have to "have some similarities".
Upvotes: 1
Reputation: 789
Decorate the adaptees and implement a common interface to represent a collection of decorated adapters?
Upvotes: 1