|
In computer programming, a facade is an object that provides a simplified interface to a larger body of code, such as a class library. A facade can: HTML and JavaScript in an IDE that uses color coding to highlight various keywords and help the developer see the function of each piece of code. ...
Illustration of an application which may use libvorbisfile. ...
- 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. In computer science, a library is a collection of subprograms used to develop software. ...
Object-oriented programming (OOP) is a computer programming paradigm in which a software system is modeled as a set of objects that interact with each other. ...
In software engineering, a design pattern is a general repeatable solution to a commonly-occurring problem in software design. ...
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. It has been suggested that this article or section be merged into Object-oriented analysis and design. ...
Examples
Java The following example hides the parts of a complicated calendar API behind a more userfriendly facade. The output is: Date: 1980-08-20 20 days after: 1980-09-09 import java.util.*; /** "Facade" */ class UserfriendlyDate { GregorianCalendar gcal; public UserfriendlyDate(String isodate_ymd) { String[] a = isodate_ymd.split("-"); gcal = new GregorianCalendar(Integer.valueOf(a[0]).intValue(), Integer.valueOf(a[1]).intValue()-1 /* !!! */, Integer.valueOf(a[2]).intValue()); } public void addDays(int days) { gcal.add(Calendar.DAY_OF_MONTH, days); } public String toString() { return new Formatter().format("%1$tY-%1$tm-%1$td", gcal).toString();} } /** "Client" */ class FacadePattern { public static void main(String[] 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 - Description from the Portland Pattern Repository
- Description by Vince Huston
- [1] Java Facade patterns
|