GoF Definition : Provides a consistent interface for a set of interfaces in a subsystem ,Facade A pattern defines a high-level interface , This interface makes this subsystem easier to use .
This model is relatively simple .
1、C# Demo code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Appearance
{
internal class Program
{
static void Main(string[] args){
Appearance xx=new Appearance();
xx.ToDo1();
Console.WriteLine("");
xx.ToDo2();
}
}
public class ObjA{
public void ToDoA(){
Console.WriteLine("ObjA Implementation ");
}
}
public class ObjB
{
public void ToDoB()
{
Console.WriteLine("ObjB Implementation ");
}
}
public class ObjC
{
public void ToDoC()
{
Console.WriteLine("ObjC Implementation ");
}
}
public class Appearance{
private ObjA objA;
private ObjB objB;
private ObjC objC;
public Appearance()
{
this.objA = new ObjA();
this.objB = new ObjB();
this.objC = new ObjC();
}
public void ToDo1() {
objA.ToDoA();
objB.ToDoB();
}
public void ToDo2()
{
objB.ToDoB();
objC.ToDoC();
}
}
}
Output results :
2、JavaScript Demo code :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Appearance mode </title>
</head>
<body>
<div id="demo"></div>
<script>
function ObjA(){
this.ToDoA=function(){
PrintInfo("ObjA Implementation ");
};
}
function ObjB(){
this.ToDoB=function(){
PrintInfo("ObjB Implementation ");
};
}
function ObjC(){
this.ToDoC=function(){
PrintInfo("ObjC Implementation ");
};
}
function Appearance(){
this.ObjA=new ObjA();
this.ObjB=new ObjB();
this.ObjC=new ObjC();
this.ToDo1=function(){
this.ObjA.ToDoA();
this.ObjB.ToDoB();
};
this.ToDo2=function(){
this.ObjB.ToDoB();
this.ObjC.ToDoC();
}
}
function PrintInfo(Str){
document.getElementById("demo").innerHTML = document.getElementById("demo").innerHTML + Str+"<br>";
}
AA=new Appearance();
AA.ToDo1();
PrintInfo("");
AA.ToDo2();
</script>
</body>
</html>
Output in web pages :
ObjA Implementation
ObjB Implementation
ObjB Implementation
ObjC Implementation
3、PHP Demo code :
<?php
class Appearance{
private $ObjA;
private $ObjB;
private $ObjC;
function __construct(){
$this->ObjA=new ObjA;
$this->ObjB=new ObjB;
$this->ObjC=new ObjC;
}
function ToDo1(){
$this->ObjA->ToDoA();
$this->ObjB->ToDoB();
}
function ToDo2(){
$this->ObjB->ToDoB();
$this->ObjC->ToDoC();
}
}
class ObjA{
function ToDoA(){
echo "ObjA Implementation .<br>";
}
}
class ObjB{
function ToDoB(){
echo "ObjB Implementation .<br>";
}
}
class ObjC{
function ToDoC(){
echo "ObjC Implementation .<br>";
}
}
$Appearance=new Appearance;
$Appearance->ToDo1();
echo "<br>";
$Appearance->ToDo2();
?>
Output in web pages :
ObjA Implementation .
ObjB Implementation .
ObjB Implementation .
ObjC Implementation .
4、Java Demo code :
class DesignAppearance{
public static void main(String[] args){
Appearance xx=new Appearance();
xx.ToDo1();
System.out.println("");
xx.ToDo2();
}
}
class ObjA{
public void ToDoA(){
System.out.println("ObjA Implementation ");
}
}
class ObjB{
public void ToDoB(){
System.out.println("ObjB Implementation ");
}
}
class ObjC{
public void ToDoC(){
System.out.println("ObjC Implementation ");
}
}
class Appearance{
private ObjA OA = new ObjA();
private ObjB OB = new ObjB();
private ObjC OC = new ObjC();
public Appearance(){
System.out.println(" initialization ");
}
public void ToDo1(){
OA.ToDoA();
OB.ToDoB();
}
public void ToDo2(){
OB.ToDoB();
OC.ToDoC();
}
}
Results output :
5、Pthon Demo code :
class ObjA:
def todoA(self):
print("ObjA Implementation ")
class ObjB:
def todoB(self):
print("ObjB Implementation ")
class ObjC:
def todoC(self):
print("ObjC Implementation ")
class Appearance:
def __init__(self):
self.AA=ObjA()
self.BB=ObjB()
self.CC=ObjC()
def todo1(self):
self.AA.todoA()
self.BB.todoB()
def todo2(self):
self.BB.todoB()
self.CC.todoC()
xx=Appearance()
xx.todo1()
print("")
xx.todo2()
Console output :
ObjA Implementation
ObjB Implementation
ObjB Implementation
ObjC Implementation