I can't decide on which pattern is best suited to the following problem.
I have a client system who will be interacting with a separate subsystem. The subsystem is quite complicated and so I need an interface between the two to simplify the client system. This sounds like a perfect fit for Facade pattern but I think Adapter pattern too fits for my problem.
Does it make any difference if the interface in the middle calls individual tasks on the subsystem through simple API calls?
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With