欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

设计模式之外观(facade)

程序员文章站 2022-05-17 19:36:37
...

public class Facade {

	class Engine{
		public void run(){
			System.out.println("engine is run...");
		}
		public void stop(){
			System.out.println("engine is stop...");
		}
	}
	class Wheel{
		public void run(){
			System.out.println("wheel is run...");
		}
		public void stop(){
			System.out.println("wheel is stop...");
		}
	}
	//向外提供一个接口
	class CarFacade{
		Engine engine = new Engine();
		Wheel wheel = new Wheel();
		public void carRun(){
			engine.run();
			wheel.run();
		}
		public void carStop(){
			engine.stop();
			engine.run();
		}
	}
	public static void main(String[] args) {
		Facade facade = new Facade();
		CarFacade car = facade.new CarFacade();
		car.carRun();
		car.carStop();
	}
}
   
 
相关标签: facade 外观模式