marți, 13 octombrie 2009

[DesignPattern] Adapter

-> Somehow we could encounter a situation that we have a class completely developed, and we are not allowed to create/modify that class, but we still want to communicate (consume) with it. In that case, we need to have an adapter to enable that class
-> Very useful for the system integration when some other components have to be adapted by the existing system.

Adapter Design Pattern Structure


- an interface for Target (class to which the non-adapted class should be adapted) : ITarget
- a class NonAdapted (does not implement ITarget)
- a class Adapter (has a field of type NonAdapted and implement ITarget using fuctionality from NonAdapter class)
- an interface ICommunicator - interface that contracts other classes to be a Communicator and gain the ability to communicate to an ITarget object

public interface ICommunicator
ITarget ObjectToTarget { get; set; }
void StartCommunication();

- a class Communicator : ICommunicator

Niciun comentariu:

Trimiteți un comentariu