Consider the following design, I doubt if I implemented Facade
design pattern in correct way. My concern is that I manipulated the simple request coming from client; and not naively delegate the request to the encapsulated type: ComplexWorker
. Is it ok? Isn't it actually the Wrapper
design pattern?
class WorkFacade
{
public void Work(SimpleRequest simpleRequest)
{
ComplexRequest = new ComplexRequest(simpleRequest);
ComplexRequest.RequestTime = DateTime.Now;
ComplexRequest.UserId = 120;
new ComplexWorker().Work(ComplexRequest, 2015, 6, 7, 23, 12, 1);
}
}
class ComplexRequest
{
ComplexRequest(SimpleRequest request)
{
// Code to convert simple request to complex request
// understandable by ComplexRequest
}
}
class ComplexWorker
{
void Work(ComplexRequest request)
{
//...
}
}
Yes, you have implemented the Façade pattern.
Whoever uses your Façade, can enjoy the benefit of not necessarily being familiar with the subsystems (ComplexRequest and ComplexWorker in your example). Meaning you have provided a high-level and unified interface for the client. This is what Façade is all about. Doing so you are taking advantage of information hiding principle.
The Wrapper pattern, or as it more commonly known - the Adapter pattern, solves another problem. It helps you make incompatible interfaces work together. It usually helps adapt an impedance match of an old component to a new system.