While interacting with groups of developer spanning across domain and companies there are some very consistent observations which can be truly be defined as a Pattern. In coding one of the most prominent word that comes across is – Facade. But is it really used the right way? It appears that its misuse surpass the value of it several times.
First let us have a look at the classical definition of Facade:
Facade Provide a simplified, improved, or more object-oriented interface to a sub-system that is overly complex (or may simply be more complex than is needed for the current use), poorly designed, a decayed legacy system, or otherwise inappropriate for the system consuming it. Façade allows for the re-use of a valuable sub-system without coupling to the specifics of its nature (Ref).
The core highlights of Facade includes:
- Translation of interface of an existing system (complex or decayed)
- Aim of Translation is simplification, re-use and de-coupling
- Yet another interface; often doesn’t break/eliminate the original interface of the system.
- Gives a facelift to poorly designed API layer by providing a consistent simplified API definition.
Now while the merits of Facade are numerous, it has got its share of pains which often lead to disastrous consequences.
- Facade itself often doesn’t have a standard interface or UML associated with it. It exposes the design with a huge risk of misinterpretation.
- Since Facade doesn’t need to implement a standard interface it is often not extendible/replaceable (though it is re-usable).
- Often designed as a set of methods to perform related sets of Job – It turns out to be promoting logical cohesion.
One of the biggest problem with facade is
Any set of methods put together with the aim or reducing code line is generally termed as Facade. In such cases, Facade is just an arbitrary interface to reduce common code; however; at the same time introduces a non-standard layer into programming
So, How do we go about Facade. A standard interface perhaps? Interestingly if I have a standard interface to implement facade becomes more like an Adapter, which incidentally turns out to be a more useful pattern. In fact several of the well defined Facade actually are implementation of Adapter. Another variation to the idea could be a Gateway patterns. So here are my recommendation.
Be Cautious in (over) using Facade. Look for alternatives like Adapter, Gateway which are less susceptible to the same problem as Facade is