Wikipedia:

façade pattern

The façade pattern is an object-oriented design pattern.

A façade is an object that provides a simplified interface to a larger body of code, such as a class library. A façade can:

  • make a software library easier to use and understand, since the façade has convenient methods for common tasks;
  • make code that uses the library more readable, for the same reason;
  • reduce dependencies of outside code on the inner workings of a library, since most code uses the façade, thus allowing more flexibility in developing the system;
  • wrap a poorly designed collection of APIs with a single well-designed API (As per task needs).

An Adapter is used when our wrapper must respect a particular interface and must support a polymorphic behavior. On the other hand, a façade is used when one wants an easier/simpler interface to work with.

Structure

Image:FacadeDesignPattern.png

Façade
The façade class interacts Packages 1, 2 & 3 with the rest of the application.
Clients
The objects using the Façade Pattern to access resources from the Packages.
Packages
Software library / API collection accessed through the Façade Class.

Examples

Java

The following example hides the parts of a complicated calendar API behind a more user friendly façade. The output is:

Date: 1980-08-20
20 days after: 1980-09-09

<source lang="java"> import java.text.*; import java.util.*;

/** "Facade" */ class UserfriendlyDate {

   Calendar cal = Calendar.getInstance();
   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    
   public UserfriendlyDate (String isodate_ymd) throws ParseException {
       Date date = sdf.parse(isodate_ymd);
       cal.setTime(date);
   }
  
   public void addDays (int days) {
       cal.add (Calendar. DAY_OF_MONTH, days); 
   }
   public String toString() { 
       return sdf.format(cal.getTime()); 
   }

}

/** "Client" */ class FacadePattern {

   public static void main(String[] args) throws ParseException
   {  
       UserfriendlyDate d = new UserfriendlyDate("1980-08-20");   
       System.out.println ("Date: " + d.toString());   
       d.addDays(20);   
       System.out.println ("20 days after: " + d.toString());
   }

} </source>

External links



 
 
 

Join the WikiAnswers Q&A community. Post a question or answer questions about "façade pattern" at WikiAnswers.

 

Copyrights:

Wikipedia. This article is licensed under the GNU Free Documentation License. It uses material from the Wikipedia article "Façade pattern" Read more

Search for answers directly from your browser with the FREE Answers.com Toolbar!  
Click here to download now. 

Get Answers your way! Check out all our free tools and products.

On this page:   E-mail   print Print  Link  

 

Keep Reading

Mentioned In: