views:

141

answers:

5

I have a question relating to the best use of a design pattern. Its probably my understanding of the patterns thats confusing things but i cant decide which pattern is best suited to the following problem.

I have a client system who will be interacting with a seperate subsystem. The subsystem is quite complicated and so i need an interface between the two to simplify for the client system. This sounds like a perfect fit for using the facade pattern but i can look at this another way and it may also fit the adapter pattern.

If it makes any difference the interface in the middle will be doing lots of little individual tasks on the subsystem through simple api calls.

+6  A: 

From your description its more in-line with the accepted definition of the Facade, but I'd say its more of a semantic debate than anything else. Facade in general is more reducing the complexity of interfacing with an entire subsystem, whereas adapter is more geared towards tweaking an existing interface or call to your specific needs (eg the basic functionality is there but the return types aren't quite what you want, etc).

kekekela
+3  A: 

This clearly seems to be a Facade pattern case your goal is simplification rather than an actual adaptation.

Façade Definition:

Provide a unified interface to a set of interfaces in a subsystem. Façade defines a higher-level interface that makes the subsystem easier to use.

Adapter Definition:

Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.

Definitions lifted from: http://dofactory.com/Patterns/Patterns.aspx

Paul Sasik
A: 

The difference between Facade and Adapter is mostly the intent.

If what you want to do is simplify the interface then you are looking at a Facade. If you want to Adapt the interface so that it can be used as something else then its an Adapter.

But really, what is the problem how you call it? My rule of thumb is if you are implementing an existing interface you probably are using the Adapter interface. If you are creating a new simplified interface its a Facade.

krolth
+1  A: 

Adapter pattern is used when you want to adapt an existing class's interface to another interface that a client expects to work with. It usually just involves delegation or translation from a method of one interface to the corresponding method of the other.

Facade is used when you want to simplify a complex system by exposing a simpler set of APIs that a client can work with. It involves translating a complex pattern of API calls into a single API call.

Your case sounds more like you need a facade than an adapter. Implementing just the adapter pattern will not give you the benefit of API simplification. In the end, it doesn't matter what you call it. And these patterns are not exclusive. You could mix both in a way that gives you the most benefit.

Samit G.
A: 

Facade deals with interface, not implementation. Its purpose is to hide internal complexity behind a single interface that appears simple on the outside.

Meet B