Encyclopedia > Facade pattern

  Article Content

Facade pattern

In computer programming, facade pattern is one of design patterns that

Intent: Provide a high-level interface that simplifies an existing subsystem.

With the facade pattern there is no pre-existing interface that the programmer must design to. There does however exist a complicated system that the programmer need only use part of.

There may be a large set of objects with broad uses that are used in conjunction to perform a few functions for client objects. The facade pattern provides a simplified interface to achieve only those functions needed without having to reference many different, complicated interfaces. The result is a simple feel to a complicated process.

Problem: A class is unwieldy to use. You don't want to be tied to that interface or implementation. Your code is becoming closely tied to a class that you don't like, or you spend a lot of time dealing with a difficult interface, or several programmers on your team have to learn a complex subject to accomplish a few simple tasks.

Solution: Write a new interface to it that translates between your simple requests and perhaps automates tedious things you do frequently.

Normally, you write for the interface of the class that you're using today, and if you have to use a different class tomorrow, you write a Proxy. With a poor or overly complex interface, you may wind up writing for a complex interface, then writing a Proxy to translate that back to a simple interface. A Facade is a neutral ground. It allows you to shuff all of the related undesired complexity should you switch classes. You can replace it with a new Facade that translates the simple interface of the first facade to the simple interface of the replacement class.

A DecoratorPattern adds complexity to the class it stands in for; a FacadePattern mitigates complexity. Both are cases of the ProxyPattern.

Conceivably, you could replace one package with a horrible interface with another package with a horrible interface. In this case, you would need to stick in an equally complex Facade, but the code using the interface could remain blissfully ignorant of the whole ordeal.

The article partly contains material from Perl Design Patterns Book

See also: design pattern, Abstract factory pattern, Mediator pattern



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Facade pattern

... The facade pattern provides a simplified interface to achieve only those functions needed without having to reference many different, complicated interfaces. The result ...