外观模式
代码
using System;
using System.Collections.Generic;
internal class Engine
{
public string EngineWork()
{
return "BMW's Engine is Working";
}
public string EngineStop()
{
return "BMW's Engine is stop";
}
}
internal class Wheel
{
public string WheelStart()
{
return "BMW's Wheel is start";
}
public string WheelStop()
{
return "BMW's Wheel is stop";
}
}
internal class Body
{
public Wheel[] wheels=new Wheel[4];
public Engine engine=new Engine();
public Body()
{
for(int i=0;i<wheels.Length;i++)
{
wheels[i]=new Wheel();
}
}
}
public class carFacade
{
Body myBody=new Body();
public void Run()
{
Console.WriteLine(myBody.engine.EngineWork());
for(int i=0;i<myBody.wheels.Length;i++)
{
Console.WriteLine(myBody.wheels[i].WheelStart());
}
}
public void Stop()
{
Console.WriteLine(myBody.engine.EngineStop());
for(int i=0;i<myBody.wheels.Length;i++)
{
Console.WriteLine(myBody.wheels[i].WheelStop());
}
}
}
public class MyClass
{
public static void Main()
{
carFacade mycarFacade=new carFacade();
mycarFacade.Run();
mycarFacade.Stop();
Console.ReadLine();
}
}
using System.Collections.Generic;
internal class Engine
{
public string EngineWork()
{
return "BMW's Engine is Working";
}
public string EngineStop()
{
return "BMW's Engine is stop";
}
}
internal class Wheel
{
public string WheelStart()
{
return "BMW's Wheel is start";
}
public string WheelStop()
{
return "BMW's Wheel is stop";
}
}
internal class Body
{
public Wheel[] wheels=new Wheel[4];
public Engine engine=new Engine();
public Body()
{
for(int i=0;i<wheels.Length;i++)
{
wheels[i]=new Wheel();
}
}
}
public class carFacade
{
Body myBody=new Body();
public void Run()
{
Console.WriteLine(myBody.engine.EngineWork());
for(int i=0;i<myBody.wheels.Length;i++)
{
Console.WriteLine(myBody.wheels[i].WheelStart());
}
}
public void Stop()
{
Console.WriteLine(myBody.engine.EngineStop());
for(int i=0;i<myBody.wheels.Length;i++)
{
Console.WriteLine(myBody.wheels[i].WheelStop());
}
}
}
public class MyClass
{
public static void Main()
{
carFacade mycarFacade=new carFacade();
mycarFacade.Run();
mycarFacade.Stop();
Console.ReadLine();
}
}