{"id":97,"date":"2008-03-04T15:35:13","date_gmt":"2008-03-04T15:35:13","guid":{"rendered":""},"modified":"2008-03-04T15:35:13","modified_gmt":"2008-03-04T15:35:13","slug":"97","status":"publish","type":"post","link":"https:\/\/www.poloo.org\/?p=97","title":{"rendered":"\u5916\u89c2\u6a21\u5f0f(Facade Pattern)"},"content":{"rendered":"<p>\u4e00\u3001 \u95e8\u9762\uff08Facade\uff09\u6a21\u5f0f<br \/>\u5916\u90e8\u4e0e\u4e00\u4e2a\u5b50\u7cfb\u7edf\u7684\u901a\u4fe1\u5fc5\u987b\u901a\u8fc7\u4e00\u4e2a\u7edf\u4e00\u7684\u95e8\u9762(Facade)\u5bf9\u8c61\u8fdb\u884c\uff0c\u8fd9\u5c31\u662f\u95e8\u9762\u6a21\u5f0f\u3002<\/p>\n<p>\u533b\u9662\u7684\u4f8b\u5b50<\/p>\n<p>\u7528\u4e00\u4e2a\u4f8b\u5b50\u8fdb\u884c\u8bf4\u660e\uff0c\u5982\u679c\u628a\u533b\u9662\u4f5c\u4e3a\u4e00\u4e2a\u5b50\u7cfb\u7edf\uff0c\u6309\u7167\u90e8\u95e8\u804c\u80fd\uff0c\u8fd9\u4e2a\u7cfb\u7edf\u53ef\u4ee5\u5212\u5206\u4e3a\u6302\u53f7\u3001\u95e8\u8bca\u3001\u5212\u4ef7\u3001\u5316\u9a8c\u3001\u6536\u8d39\u3001\u53d6\u836f\u7b49\u3002\u770b\u75c5\u7684\u75c5\u4eba\u8981\u4e0e\u8fd9\u4e9b\u90e8\u95e8\u6253\u4ea4\u9053\uff0c\u5c31\u5982\u540c\u4e00\u4e2a\u5b50\u7cfb\u7edf\u7684\u5ba2\u6237\u7aef\u4e0e\u4e00\u4e2a\u5b50\u7cfb\u7edf\u7684\u5404\u4e2a\u7c7b\u6253\u4ea4\u9053\u4e00\u6837\uff0c\u4e0d\u662f\u4e00\u4ef6\u5bb9\u6613\u7684\u4e8b\u60c5\u3002<\/p>\n<p>\u9996\u5148\u75c5\u4eba\u5fc5\u987b\u5148\u6302\u53f7\uff0c\u7136\u540e\u95e8\u8bca\u3002\u5982\u679c\u533b\u751f\u8981\u6c42\u5316\u9a8c\uff0c\u75c5\u4eba\u5fc5\u987b\u9996\u5148\u5212\u4ef7\uff0c\u7136\u540e\u7f34\u6b3e\uff0c\u624d\u80fd\u5230\u5316\u9a8c\u90e8\u95e8\u505a\u5316\u9a8c\u3002\u5316\u9a8c\u540e\uff0c\u518d\u56de\u5230\u95e8\u8bca\u5ba4\u3002<\/p>\n<p>\u89e3\u51b3\u8fd9\u79cd\u4e0d\u4fbf\u7684\u65b9\u6cd5\u4fbf\u662f\u5f15\u8fdb\u95e8\u9762\u6a21\u5f0f\u3002\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a\u63a5\u5f85\u5458\u7684\u4f4d\u7f6e\uff0c\u7531\u63a5\u5f85\u5458\u8d1f\u8d23\u4ee3\u4e3a\u6302\u53f7\u3001\u5212\u4ef7\u3001\u7f34\u8d39\u3001\u53d6\u836f\u7b49\u3002\u8fd9\u4e2a\u63a5\u5f85\u5458\u5c31\u662f\u95e8\u9762\u6a21\u5f0f\u7684\u4f53\u73b0\uff0c\u75c5\u4eba\u53ea\u63a5\u89e6\u63a5\u5f85\u5458\uff0c\u7531\u63a5\u5f85\u5458\u8d1f\u8d23\u4e0e\u533b\u9662\u7684\u5404\u4e2a\u90e8\u95e8\u6253\u4ea4\u9053\u3002<\/p>\n<p>\u4ec0\u4e48\u662f\u95e8\u9762\u6a21\u5f0f<\/p>\n<p>\u95e8\u9762\u6a21\u5f0f\u8981\u6c42\u4e00\u4e2a\u5b50\u7cfb\u7edf\u7684\u5916\u90e8\u4e0e\u5176\u5185\u90e8\u7684\u901a\u4fe1\u5fc5\u987b\u901a\u8fc7\u4e00\u4e2a\u7edf\u4e00\u7684\u95e8\u9762(Facade)\u5bf9\u8c61\u8fdb\u884c\u3002\u95e8\u9762\u6a21\u5f0f\u63d0\u4f9b\u4e00\u4e2a\u9ad8\u5c42\u6b21\u7684\u63a5\u53e3\uff0c\u4f7f\u5f97\u5b50\u7cfb\u7edf\u66f4\u6613\u4e8e\u4f7f\u7528\u3002<\/p>\n<p>\u5c31\u5982\u540c\u533b\u9662\u7684\u63a5\u5f85\u5458\u4e00\u6837\uff0c\u95e8\u9762\u6a21\u5f0f\u7684\u95e8\u9762\u7c7b\u5c06\u5ba2\u6237\u7aef\u4e0e\u5b50\u7cfb\u7edf\u7684\u5185\u90e8\u590d\u6742\u6027\u5206\u9694\u5f00\uff0c\u4f7f\u5f97\u5ba2\u6237\u7aef\u53ea\u9700\u8981\u4e0e\u95e8\u9762\u5bf9\u8c61\u6253\u4ea4\u9053\uff0c\u800c\u4e0d\u9700\u8981\u4e0e\u5b50\u7cfb\u7edf\u5185\u90e8\u7684\u5f88\u591a\u5bf9\u8c61\u6253\u4ea4\u9053\u3002<\/p>\n<p>\u4e8c\u3001 \u95e8\u9762\u6a21\u5f0f\u7684\u7ed3\u6784<br \/>\u95e8\u9762\u6a21\u5f0f\u662f\u5bf9\u8c61\u7684\u7ed3\u6784\u6a21\u5f0f\u3002\u95e8\u9762\u6a21\u5f0f\u6ca1\u6709\u4e00\u4e2a\u4e00\u822c\u5316\u7684\u7c7b\u56fe\u63cf\u8ff0\uff0c\u4e0b\u56fe\u6f14\u793a\u4e86\u4e00\u4e2a\u95e8\u9762\u6a21\u5f0f\u7684\u793a\u610f\u6027\u5bf9\u8c61\u56fe\uff1a<br \/><img decoding=\"async\" src=\"http:\/\/www.poloo.org\/wp-content\/attachments\/month_0803\/a200834153331.gif\" \/><br \/>\u5728\u8fd9\u4e2a\u5bf9\u8c61\u56fe\u4e2d\uff0c\u51fa\u73b0\u4e86\u4e24\u4e2a\u89d2\u8272\uff1a<\/p>\n<p>\u95e8\u9762(Facade)\u89d2\u8272\uff1a\u5ba2\u6237\u7aef\u53ef\u4ee5\u8c03\u7528\u8fd9\u4e2a\u89d2\u8272\u7684\u65b9\u6cd5\u3002\u6b64\u89d2\u8272\u77e5\u6653\u76f8\u5173\u7684(\u4e00\u4e2a\u6216\u8005\u591a\u4e2a)\u5b50\u7cfb\u7edf\u7684\u529f\u80fd\u548c\u8d23\u4efb\u3002\u5728\u6b63\u5e38\u60c5\u51b5\u4e0b\uff0c\u672c\u89d2\u8272\u4f1a\u5c06\u6240\u6709\u4ece\u5ba2\u6237\u7aef\u53d1\u6765\u7684\u8bf7\u6c42\u59d4\u6d3e\u5230\u76f8\u5e94\u7684\u5b50\u7cfb\u7edf\u53bb\u3002<\/p>\n<p>\u5b50\u7cfb\u7edf(subsystem)\u89d2\u8272\uff1a\u53ef\u4ee5\u540c\u65f6\u6709\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u5b50\u7cfb\u7edf\u3002\u6bcf\u4e00\u4e2a\u5b50\u7cfb\u7edf\u90fd\u4e0d\u662f\u4e00\u4e2a\u5355\u72ec\u7684\u7c7b\uff0c\u800c\u662f\u4e00\u4e2a\u7c7b\u7684\u96c6\u5408\u3002\u6bcf\u4e00\u4e2a\u5b50\u7cfb\u7edf\u90fd\u53ef\u4ee5\u88ab\u5ba2\u6237\u7aef\u76f4\u63a5\u8c03\u7528\uff0c\u6216\u8005\u88ab\u95e8\u9762\u89d2\u8272\u8c03\u7528\u3002\u5b50\u7cfb\u7edf\u5e76\u4e0d\u77e5\u9053\u95e8\u9762\u7684\u5b58\u5728\uff0c\u5bf9\u4e8e\u5b50\u7cfb\u7edf\u800c\u8a00\uff0c\u95e8\u9762\u4ec5\u4ec5\u662f\u53e6\u5916\u4e00\u4e2a\u5ba2\u6237\u7aef\u800c\u5df2\u3002<\/p>\n<p>\u4e09\u3001 \u95e8\u9762\u6a21\u5f0f\u7684\u5b9e\u73b0<br \/>\u4e00\u4e2a\u7cfb\u7edf\u53ef\u4ee5\u6709\u51e0\u4e2a\u95e8\u9762\u7c7b<\/p>\n<p>\u3010GOF\u3011\u7684\u4e66\u4e2d\u6307\u51fa\uff1a\u5728\u95e8\u9762\u6a21\u5f0f\u4e2d\uff0c\u901a\u5e38\u53ea\u9700\u8981\u4e00\u4e2a\u95e8\u9762\u7c7b\uff0c\u5e76\u4e14\u6b64\u95e8\u9762\u7c7b\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u6362\u8a00\u4e4b\u5b83\u662f\u4e00\u4e2a\u5355\u4f8b\u7c7b\u3002\u5f53\u7136\u8fd9\u5e76\u4e0d\u610f\u5473\u7740\u5728\u6574\u4e2a\u7cfb\u7edf\u91cc\u53ea\u80fd\u6709\u4e00\u4e2a\u95e8\u9762\u7c7b\uff0c\u800c\u4ec5\u4ec5\u662f\u8bf4\u5bf9\u6bcf\u4e00\u4e2a\u5b50\u7cfb\u7edf\u53ea\u6709\u4e00\u4e2a\u95e8\u9762\u7c7b\u3002\u6216\u8005\u8bf4\uff0c\u5982\u679c\u4e00\u4e2a\u7cfb\u7edf\u6709\u597d\u51e0\u4e2a\u5b50\u7cfb\u7edf\u7684\u8bdd\uff0c\u6bcf\u4e00\u4e2a\u5b50\u7cfb\u7edf\u6709\u4e00\u4e2a\u95e8\u9762\u7c7b\uff0c\u6574\u4e2a\u7cfb\u7edf\u53ef\u4ee5\u6709\u6570\u4e2a\u95e8\u9762\u7c7b\u3002<\/p>\n<p>\u4e3a\u5b50\u7cfb\u7edf\u589e\u52a0\u65b0\u884c\u4e3a<\/p>\n<p>\u521d\u5b66\u8005\u5f80\u5f80\u4ee5\u4e3a\u901a\u8fc7\u7ee7\u627f\u4e00\u4e2a\u95e8\u9762\u7c7b\u4fbf\u53ef\u5728\u5b50\u7cfb\u7edf\u4e2d\u52a0\u5165\u65b0\u7684\u884c\u4e3a\uff0c\u8fd9\u662f\u9519\u8bef\u7684\u3002\u95e8\u9762\u6a21\u5f0f\u7684\u7528\u610f\u662f\u4e3a\u5b50\u7cfb\u7edf\u63d0\u4f9b\u4e00\u4e2a\u96c6\u4e2d\u5316\u548c\u7b80\u5316\u7684\u6c9f\u901a\u7ba1\u9053\uff0c\u800c\u4e0d\u80fd\u5411\u5b50\u7cfb\u7edf\u52a0\u5165\u65b0\u7684\u884c\u4e3a\u3002<\/p>\n<p>\u56db\u3001 \u5728\u4ec0\u4e48\u60c5\u51b5\u4e0b\u4f7f\u7528\u95e8\u9762\u6a21\u5f0f<br \/>\u4e3a\u4e00\u4e2a\u590d\u6742\u5b50\u7cfb\u7edf\u63d0\u4f9b\u4e00\u4e2a\u7b80\u5355\u63a5\u53e3 <br \/>\u63d0\u9ad8\u5b50\u7cfb\u7edf\u7684\u72ec\u7acb\u6027 <br \/>\u5728\u5c42\u6b21\u5316\u7ed3\u6784\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Facade\u6a21\u5f0f\u5b9a\u4e49\u7cfb\u7edf\u4e2d\u6bcf\u4e00\u5c42\u7684\u5165\u53e3\u3002 <\/p>\n<p>\u4e94\u3001 \u4e00\u4e2a\u4f8b\u5b50<br \/>\u6211\u4eec\u8003\u5bdf\u4e00\u4e2a\u4fdd\u5b89\u7cfb\u7edf\u7684\u4f8b\u5b50\uff0c\u4ee5\u8bf4\u660e\u95e8\u9762\u6a21\u5f0f\u7684\u529f\u6548\u3002\u4e00\u4e2a\u4fdd\u5b89\u7cfb\u7edf\u7531\u4e24\u4e2a\u5f55\u50cf\u673a\u3001\u4e09\u4e2a\u7535\u706f\u3001\u4e00\u4e2a\u9065\u611f\u5668\u548c\u4e00\u4e2a\u8b66\u62a5\u5668\u7ec4\u6210\u3002\u4fdd\u5b89\u7cfb\u7edf\u7684\u64cd\u4f5c\u4eba\u5458\u9700\u8981\u7ecf\u5e38\u5c06\u8fd9\u4e9b\u4eea\u5668\u542f\u52a8\u548c\u5173\u95ed\u3002<\/p>\n<p>\u4e0d\u4f7f\u7528\u95e8\u9762\u6a21\u5f0f\u7684\u8bbe\u8ba1<\/p>\n<p>\u9996\u5148\uff0c\u5728\u4e0d\u4f7f\u7528\u95e8\u9762\u6a21\u5f0f\u7684\u60c5\u51b5\u4e0b\uff0c\u64cd\u4f5c\u8fd9\u4e2a\u4fdd\u5b89\u7cfb\u7edf\u7684\u64cd\u4f5c\u5458\u5fc5\u987b\u76f4\u63a5\u64cd\u4f5c\u6240\u6709\u7684\u8fd9\u4e9b\u90e8\u4ef6\u3002\u4e0b\u56fe\u6240\u793a\u5c31\u662f\u5728\u4e0d\u4f7f\u7528\u95e8\u9762\u6a21\u5f0f\u7684\u60c5\u51b5\u4e0b\u7cfb\u7edf\u7684\u8bbe\u8ba1\u56fe\u3002<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/www.poloo.org\/wp-content\/attachments\/month_0803\/j200834153340.gif\" \/><br \/>\u53ef\u4ee5\u770b\u51fa\uff0cClient\u5bf9\u8c61\u9700\u8981\u5f15\u7528\u5230\u6240\u6709\u7684\u5f55\u50cf\u673a(Camera)\u3001\u7535\u706f(Light)\u3001\u611f\u5e94\u5668(Sensor)\u548c\u8b66\u62a5\u5668(Alarm)\u5bf9\u8c61\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<br \/><code>using System;<\/p>\n<p>public class Camera<br \/>{<br \/>&nbsp;&nbsp;public void TurnOn()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Turning on the camera.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void TurnOff()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Turning off the camera.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void Rotate(int degrees)<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Rotating the camera by {0} degrees.\", degrees);<br \/>&nbsp;&nbsp;}<br \/>}<\/p>\n<p>public class Light<br \/>{<\/p>\n<p>&nbsp;&nbsp;public void TurnOff()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Turning on the light.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void TurnOn()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Turning off the light.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void ChangeBulb()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"changing the light-bulb.\");<br \/>&nbsp;&nbsp;}<br \/>}<\/p>\n<p>public class Sensor<br \/>{<br \/>&nbsp;&nbsp;public void Activate()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Activating the sensor.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void Deactivate()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Deactivating the sensor.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void Trigger()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"The sensor has triggered.\");<br \/>&nbsp;&nbsp;}<br \/>}<\/p>\n<p>public class Alarm<br \/>{<\/p>\n<p>&nbsp;&nbsp;public void Activate()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Activating the alarm.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void Deactivate()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Deactivating the alarm.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void Ring()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Ringing the alarm.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void StopRing()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Stop the alarm.\");<br \/>&nbsp;&nbsp;}<br \/>}<\/p>\n<p>public class Client<br \/>{<br \/>&nbsp;&nbsp;private static Camera camera1, camera2;<br \/>&nbsp;&nbsp;private static Light light1, light2, light3;<br \/>&nbsp;&nbsp;private static Sensor sensor;<br \/>&nbsp;&nbsp;private static Alarm alarm;<\/p>\n<p>&nbsp;&nbsp;static Client()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;camera1 = new Camera();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;camera2 = new Camera();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light1 = new Light();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light2 = new Light();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light3 = new Light();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;sensor = new Sensor();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;alarm = new Alarm();<br \/>&nbsp;&nbsp;}&nbsp;&nbsp;<\/p>\n<p>&nbsp;&nbsp;public static void Main( string[] args )<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;camera1.TurnOn();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;camera2.TurnOn();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light1.TurnOn();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light2.TurnOn();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light3.TurnOn();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;sensor.Activate();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;alarm.Activate();<br \/>&nbsp;&nbsp;}<br \/>}<br \/><\/code> <\/p>\n<p>\u516d\u3001 \u4f7f\u7528\u95e8\u9762\u6a21\u5f0f\u7684\u8bbe\u8ba1<br \/>\u4e00\u4e2a\u5408\u60c5\u5408\u7406\u7684\u6539\u8fdb\u65b9\u6cd5\u5c31\u662f\u51c6\u5907\u4e00\u4e2a\u7cfb\u7edf\u7684\u63a7\u5236\u53f0\uff0c\u4f5c\u4e3a\u4fdd\u5b89\u7cfb\u7edf\u7684\u7528\u6237\u754c\u9762\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a<br \/><img decoding=\"async\" src=\"http:\/\/www.poloo.org\/wp-content\/attachments\/month_0803\/d20083415349.gif\" \/><br \/>\u7a0b\u5e8f\u4ee3\u7801\u5982\u4e0b\uff1a<br \/><code><br \/>using System;<\/p>\n<p>public class Camera<br \/>{<br \/>&nbsp;&nbsp;public void TurnOn()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Turning on the camera.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void TurnOff()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Turning off the camera.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void Rotate(int degrees)<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Rotating the camera by {0} degrees.\", degrees);<br \/>&nbsp;&nbsp;}<br \/>}<\/p>\n<p>public class Light<br \/>{<\/p>\n<p>&nbsp;&nbsp;public void TurnOff()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Turning on the light.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void TurnOn()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Turning off the light.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void ChangeBulb()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"changing the light-bulb.\");<br \/>&nbsp;&nbsp;}<br \/>}<\/p>\n<p>public class Sensor<br \/>{<br \/>&nbsp;&nbsp;public void Activate()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Activating the sensor.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void Deactivate()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Deactivating the sensor.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void Trigger()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"The sensor has triggered.\");<br \/>&nbsp;&nbsp;}<br \/>}<\/p>\n<p>public class Alarm<br \/>{<\/p>\n<p>&nbsp;&nbsp;public void Activate()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Activating the alarm.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void Deactivate()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Deactivating the alarm.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void Ring()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Ringing the alarm.\");<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void StopRing()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"Stop the alarm.\");<br \/>&nbsp;&nbsp;}<br \/>}<\/p>\n<p>public class SecurityFacade<br \/>{<br \/>&nbsp;&nbsp;private static Camera camera1, camera2;<br \/>&nbsp;&nbsp;private static Light light1, light2, light3;<br \/>&nbsp;&nbsp;private static Sensor sensor;<br \/>&nbsp;&nbsp;private static Alarm alarm;<\/p>\n<p>&nbsp;&nbsp;static SecurityFacade()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;camera1 = new Camera();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;camera2 = new Camera();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light1 = new Light();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light2 = new Light();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light3 = new Light();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;sensor = new Sensor();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;alarm = new Alarm();<br \/>&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;<br \/>&nbsp;&nbsp;public void Activate()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;camera1.TurnOn();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;camera2.TurnOn();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light1.TurnOn();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light2.TurnOn();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light3.TurnOn();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;sensor.Activate();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;alarm.Activate();<br \/>&nbsp;&nbsp;}<\/p>\n<p>&nbsp;&nbsp;public void Deactivate()<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;camera1.TurnOff();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;camera2.TurnOff();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light1.TurnOff();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light2.TurnOff();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;light3.TurnOff();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;sensor.Deactivate();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;alarm.Deactivate();<br \/>&nbsp;&nbsp;}<br \/>}<\/p>\n<p>public class Client<br \/>{<br \/>&nbsp;&nbsp;private static SecurityFacade security;<\/p>\n<p>&nbsp;&nbsp;public static void Main( string[] args )<br \/>&nbsp;&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;security = new SecurityFacade();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;security.Activate();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;Console.WriteLine(\"<br \/>\n--------------------<br \/>\n\");<br \/>&nbsp;&nbsp;&nbsp;&nbsp;security.Deactivate();<br \/>&nbsp;&nbsp;}<br \/>}<br \/><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001 \u95e8\u9762\uff08Facade\uff09\u6a21\u5f0f\u5916\u90e8\u4e0e\u4e00\u4e2a\u5b50\u7cfb\u7edf\u7684\u901a\u4fe1\u5fc5\u987b\u901a\u8fc7\u4e00\u4e2a\u7edf\u4e00&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-97","post","type-post","status-publish","format-standard","hentry","category-Note"],"_links":{"self":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/97","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=97"}],"version-history":[{"count":0,"href":"https:\/\/www.poloo.org\/index.php?rest_route=\/wp\/v2\/posts\/97\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.poloo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}