Facade Pattern Article Index for
Facade
Website Links For
Facade
 

Information About

Facade Pattern




  • make a Software Library easier to use and understand, since the facade 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 facade, thus allowing more flexibility in developing the system;

  • wrap a poorly designed collection of APIs with a single well-designed API.


The facade is an Object-oriented Design Pattern .

Facades are very common in Object-oriented Design . For example, the Java standard library contains dozens of classes for parsing font files and rendering text into geometric outlines and ultimately into pixels. However, most Java programmers are unaware of these details, because the library also contains facade classes (Font and Graphics) that offer simple methods for the most common font-related operations.


EXAMPLES



Java


The output of the following example which hides parts of a complicate calendar API behind a more userfriendly facade is:
''Date: 1980-08-20''
''20 days after: 1980-09-09''

  • ;


  • --- "Facade" ---/''

  • class UserfriendlyDate

{
GregorianCalendar gcal;

public UserfriendlyDate(String isodate_ymd) {
String {Link without Title} a = isodate_ymd.split("-");
gcal = new GregorianCalendar(Integer.valueOf(a {Link without Title} ),
  • !!! ---/, Integer.valueOf(a[2 ));

  • }

public void addDays(int days) { gcal.add(Calendar.DAY_OF_MONTH, days); }
public String toString() { return new Formatter().format("%1-%1-%1", gcal); }
}

  • --- "Client" ---/''

  • class FacadePattern

{
public static void main(String {Link without Title} args)
{
UserfriendlyDate d = new UserfriendlyDate("1980-08-20");
System.out.println("Date: "+d);
d.addDays(20);
System.out.println("20 days after: "+d);
}
}


EXTERNAL LINKS