Changes

Jump to: navigation, search

Facade

3,437 bytes added, 11:38, 19 March 2007
no edit summary
== Facade Pattern ==
The Facade Pattern is used to consolidate numerous complicated objects and function calls in a single interface. It does not necessarily encapsulate the objects behind the facade, as it commonly allows the client to work directly with the object. A facade is like a house. Someone walking by the house sees the exterior and knows the functionality contained within the house (shelter, kitchen, bathroom, bedrooms, etc), but does not know how they are set up or laid out (ie implemented). The person walking by can approach the house and interact with its functionality through the front door, which is the single point of access to that which is contained within the house (ie sub-system).
== UML Example ==
<center>[[Image:FacadeDesignPattern.png]]</center><br/>
[http://en.wikipedia.org/wiki/Image:FacadeDesignPattern.png|Wikipedia, used under GNU FDL]
== Code Examples ==
=== Java ===
[http://www.fluffycat.com/Java-Design-Patterns/Facade/|Java Design Patterns Facade]
<pre>
public class FacadeCuppaMaker {
boolean teaBagIsSteeped;
public FacadeCuppaMaker() {
System.out.println(
"FacadeCuppaMaker ready to make you a cuppa!");
}
public FacadeTeaCup makeACuppa() {
FacadeTeaCup cup = new FacadeTeaCup();
FacadeTeaBag teaBag = new FacadeTeaBag();
FacadeWater water = new FacadeWater();
cup.addFacadeTeaBag(teaBag);
water.boilFacadeWater();
cup.addFacadeWater(water);
cup.steepTeaBag();
return cup;
}
}
</pre>
=== C++ PHP5 ===[http://www.devshed.com/c/a/PHP/Introducing-the-Facade-Pattern-in-PHP-5/2/|DevShed Introducing Facade Pattern in PHP5]<pre>// define 'CompressContentFacade' classclass CompressContentFacade{ public static function stripContent($content){ // remove new lines from content $strippedContent=StripContent::stripString($content); // compress content by using GZIP algorithm $gzippedContent=GzipContent::compressString($strippedContent); return $gzippedContent; }}</pre>
=== C# .NET ===
[http://www.dofactory.com/Patterns/PatternFacade.aspx#_self1|Facade Design Pattern in C# (via Data & Object Factory)]]
<pre> // Facade pattern -- Structural example
 
using System;
namespace DoFactory.GangOfFour.Facade.Structural
{
// Mainapp test application
class MainApp
{
public static void Main()
{
Facade facade = new Facade();
facade.MethodA();
facade.MethodB();
// Wait for user
Console.Read();
}
}
// "Subsystem ClassA"
class SubSystemOne
{
public void MethodOne()
{
Console.WriteLine(" SubSystemOne Method");
}
}
// Subsystem ClassB"
class SubSystemTwo
{
public void MethodTwo()
{
Console.WriteLine(" SubSystemTwo Method");
}
}
// Subsystem ClassC"
class SubSystemThree
{
public void MethodThree()
{
Console.WriteLine(" SubSystemThree Method");
}
}
// Subsystem ClassD"
class SubSystemFour
{
public void MethodFour()
{
Console.WriteLine(" SubSystemFour Method");
}
}
// "Facade"
class Facade
{
SubSystemOne one;
SubSystemTwo two;
SubSystemThree three;
SubSystemFour four;
 
public Facade()
{
one = new SubSystemOne();
two = new SubSystemTwo();
three = new SubSystemThree();
four = new SubSystemFour();
}
public void MethodA()
{
Console.WriteLine("\nMethodA() ---- ");
one.MethodOne();
two.MethodTwo();
four.MethodFour();
}
public void MethodB()
{
Console.WriteLine("\nMethodB() ---- ");
two.MethodTwo();
three.MethodThree();
}
}
}
</pre>
 
=== VB .NET ===
== Open Source Applications ==
=== Apache Excalibur ===
[http://www.google.com/codesearch?hl=en&q=+facade+show:1y0Eke5phF0:4pzQJEULGSg:mi9_qGoVUJU&sa=N&cd=3&ct=rc&cs_p=https://svn.apache.org/repos/asf/excalibur/trunk&cs_f=containerkit/logger/src/java/org/apache/avalon/excalibur/logger/Facade.java#a0|Apache Excalibur Facade Class Code (via Google! Code Search) ]
<pre>
/**
=== Apache Tomcat ===
[http://www.google.com/codesearch?hl=en&q=show:hGyxCO8zbbo:dtgwsf4Jsds:mEr-jpM3hx4&sa=N&ct=rd&cs_p=http://download.nextag.com/apache/tomcat/tomcat-5/v5.5.17/src/apache-tomcat-5.5.17-src.tar.gz&cs_f=apache-tomcat-5.5.17-src/connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequestFacade.java|Apache Excalibur Facade Class Code (via Google! Code Search)]<br/>
[http:<p>Serves to wrap the ServeltRequest object<//www.google.com/codesearch?hl=en&q=show:hGyxCO8zbbo:dtgwsf4Jsds:mEr-jpM3hx4&sa=N&ct=rd&cs_p=http://download.nextag.com/apache/tomcat/tomcat-5/v5.5.17/src/apache-tomcat-5.5.17-src.tar.gz&cs_f=apache-tomcat-5.5.17-src/connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequestFacade.java | Apache ]p><pre>/*
* Copyright 1999-2004 The Apache Software Foundation
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
[http://www.google.com/codesearch?hl=en&q=show:hGyxCO8zbbo:dtgwsf4Jsds:mEr-jpM3hx4&sa=N&ct=rd&cs_p=http://download.nextag.com/apache/tomcat/tomcat-5/v5.5.17/src/apache-tomcat-5.5.17-src.tar.gz&cs_f=apache-tomcat-5.5.17-src/connectors/coyote/src/java/org/apache/coyote/tomcat4/CoyoteRequestFacade.java|Apache Tomcat CoyoteRequestFacade Class Code (via Google! Code Search)]<br/>
[http://www.dofactory.com/Patterns/PatternFacade.aspx#_self1|Facade Design Pattern in C# and VB.NET]
[http://www.devshed.com/c/a/PHP/Introducing-the-Facade-Pattern-in-PHP-5/2/|DevShed Introducing Facade Pattern in PHP5]
[http://www.fluffycat.com/Java-Design-Patterns/Facade/|Java Design Patterns Facade]
1
edit

Navigation menu