程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Appearance mode of design mode (C / JavaScript / PHP / Java / Python demo code)

編輯:Python

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 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved