类别:
Structural Pattern
问题/动机:
系统非常复杂
隐藏复杂细节,提供简单界面
方案:
示例:
/* Complex parts */ public class FacadePatternDemo { public static void main(String[] args) { CarFacade facade = new CarFacade(); facade.CreateCompleteCar(); } } // The 'Subsystem ClassA' class class CarModel { public void SetModel() { System.out.println(" CarModel - SetModel"); } } /// <summary> /// The 'Subsystem ClassB' class /// </summary> class CarEngine { public void SetEngine() { System.out.println(" CarEngine - SetEngine"); } } // The 'Subsystem ClassC' class class CarBody { public void SetBody() { System.out.println(" CarBody - SetBody"); } } // The 'Subsystem ClassD' class class CarAccessories { public void SetAccessories() { System.out.println(" CarAccessories - SetAccessories"); } } // The 'Facade' class class CarFacade { private CarAccessories accessories; private CarBody body; private CarEngine engine; private CarModel model; public CarFacade() { accessories = new CarAccessories(); body = new CarBody(); engine = new CarEngine(); model = new CarModel(); } public void CreateCompleteCar() { System.out.println("******** Creating a Car **********"); model.SetModel(); engine.SetEngine(); body.SetBody(); accessories.SetAccessories(); System.out.println("******** Car creation is completed. **********"); } }
******** Creating a Car ********** CarModel - SetModel CarEngine - SetEngine CarBody - SetBody CarAccessories - SetAccessories ******** Car creation is completed. **********
应用:
不足:(
优化:)
标签:11,Pattern,void,System,class,println,Facade,public,out From: https://www.cnblogs.com/zno2/p/6694838.html