门面模式(外观模式)

1.提供一个类,封装对子系统的操作,使子系统更加容易使用

2.提供多个子系统,增加门面类可以减少各子系统间的依赖

3.客户端只需要关注门面类中方法,而不用关心子系统

 

// sub System
	class design_mode_Facade_Sub_System1
	{
		public  void design_mode_Facade_Sub_System1_Method()
		{
			System.out.println("This is design_mode_Facade_Sub_System1_Method");
		}
	}

	class design_mode_Facade_Sub_System2
	{
		public  void design_mode_Facade_Sub_System2_Method()
		{
			System.out.println("This is design_mode_Facade_Sub_System2_Method");
		}
	}

	class design_mode_Facade_Sub_System3
	{
		public  void design_mode_Facade_Sub_System3_Method()
		{
			System.out.println("This is design_mode_Facade_Sub_System3_Method");
		}
	}
   

   // 门面类
	class design_mode_Facade_Model
	{
		private design_mode_Facade_Sub_System1 sub1 = null;
		private design_mode_Facade_Sub_System2 sub2 = null;
		private design_mode_Facade_Sub_System3 sub3 = null;


		public design_mode_Facade_Model()
		{
			sub1 = new design_mode_Facade_Sub_System1();
			sub2 = new design_mode_Facade_Sub_System2();
			sub3 = new design_mode_Facade_Sub_System3();

		}

		public void design_mode_Facade_Model_MethodA()
		{
			System.out.println("方法A");
			sub1.design_mode_Facade_Sub_System1_Method();
			sub2.design_mode_Facade_Sub_System2_Method();
		}

			public void design_mode_Facade_Model_MethodB()
		{
				System.out.println("方法B");
			sub2.design_mode_Facade_Sub_System2_Method();
			sub3.design_mode_Facade_Sub_System3_Method();
		}
	}

	class design_mode_Facade_Model_Client
	{
		public void design_mode_Facade_Model_Client_Test()
		{
			design_mode_Facade_Model demod = new design_mode_Facade_Model();

			demod.design_mode_Facade_Model_MethodA();
			demod.design_mode_Facade_Model_MethodB();

		}
	}

 

你可能感兴趣的:(外观模式)