{"id":692,"date":"2020-03-18T09:59:10","date_gmt":"2020-03-18T01:59:10","guid":{"rendered":"http:\/\/blog.xrhoujie.com\/?p=692"},"modified":"2020-03-10T13:52:46","modified_gmt":"2020-03-10T05:52:46","slug":"%e4%ba%8c%e5%8d%81%e4%b8%89%e7%a7%8d%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e8%bd%ac","status":"publish","type":"post","link":"http:\/\/blog.xrhoujie.com\/?p=692","title":{"rendered":"\u4e8c\u5341\u4e09\u79cd\u8bbe\u8ba1\u6a21\u5f0f(\u8f6c)"},"content":{"rendered":"<h2 id=\"blogTitle0\">\u4e00\u3001\u521b\u5efa\u578b\uff1a<\/h2>\n<p>\u5355\u4f8b\u6a21\u5f0f\u3001\u5de5\u5382\u6a21\u5f0f\u3001\u62bd\u8c61\u5de5\u5382\u6a21\u5f0f\u3001\u539f\u578b\u6a21\u5f0f\u3001\u5efa\u9020\u8005\u6a21\u5f0f\uff1b<\/p>\n<p><img src=\"https:\/\/images2018.cnblogs.com\/blog\/1367382\/201806\/1367382-20180601225851739-1580172067.png\" alt=\"\" \/><\/p>\n<h2 id=\"blogTitle1\">\u4e8c\u3001\u7ed3\u6784\u578b\uff1a<\/h2>\n<p>\u4ee3\u7406\u6a21\u5f0f,\u88c5\u9970\u5668\u6a21\u5f0f\u3001\u9002\u914d\u5668\u6a21\u5f0f\u3001\u5916\u89c2\u6a21\u5f0f\u3001\u7ec4\u5408\u6a21\u5f0f\u3001\u4eab\u5143\u6a21\u5f0f\u3001\u6865\u6881\u6a21\u5f0f\uff1b<\/p>\n<p><img src=\"https:\/\/images2018.cnblogs.com\/blog\/1367382\/201806\/1367382-20180601230010771-1702276802.png\" alt=\"\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"blogTitle2\">\u4e09\u3001\u884c\u4e3a\u578b\uff1a<\/h2>\n<p>\u7b56\u7565\u6a21\u5f0f\u3001\u8d23\u4efb\u94fe\u6a21\u5f0f\u3001\u547d\u4ee4\u6a21\u5f0f\u3001\u4e2d\u4ecb\u8005\u6a21\u5f0f\u3001\u6a21\u677f\u65b9\u6cd5\u6a21\u5f0f\u3001\u8fed\u4ee3\u5668\u6a21\u5f0f\u3001\u8bbf\u95ee\u8005\u6a21\u5f0f\u3001\u89c2\u5bdf\u8005\u6a21\u5f0f\u3001\u89e3\u91ca\u5668\u6a21\u5f0f\u3001\u5907\u5fd8\u5f55\u6a21\u5f0f\u3001\u72b6\u6001\u6a21\u5f0f\u3002<\/p>\n<p>&nbsp;<\/p>\n<p><img src=\"https:\/\/images2018.cnblogs.com\/blog\/1367382\/201806\/1367382-20180601230031142-1478270664.png\" alt=\"\" \/><\/p>\n<h2 id=\"blogTitle3\">\u4e09\u7c7b\u8bbe\u8ba1\u6a21\u5f0f\u7684\u7279\u70b9\uff1a<\/h2>\n<p><img src=\"https:\/\/images2018.cnblogs.com\/blog\/1367382\/201806\/1367382-20180601230115927-1366562247.jpg\" alt=\"\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h1>\u516d\u5927\u539f\u5219<\/h1>\n<h2 id=\"blogTitle4\">\u4e00\u3001\u5f00\u653e\u5c01\u95ed\uff08\u7b80\u79f0\u5f00\u95ed\uff09\u539f\u5219<\/h2>\n<p>Open-Close Principle\uff08OCP\uff09\uff1a\u4e00\u4e2a\u8f6f\u4ef6\u5b9e\u4f53\u5982\u7c7b\u3001\u6a21\u5757\u548c\u51fd\u6570\u5e94\u8be5\u5bf9\u6269\u5c55\u5f00\u653e\uff0c\u5bf9\u4fee\u6539\u5173\u95ed\u3002\u76ee\u7684\u5c31\u662f\u4fdd\u8bc1\u7a0b\u5e8f\u7684\u6269\u5c55\u6027\u597d\uff0c\u6613\u4e8e\u7ef4\u62a4\u548c\u5347\u7ea7\u3002<\/p>\n<p>\u5f00\u95ed\u539f\u5219\u88ab\u79f0\u4e3a\u9762\u5411\u5bf9\u8c61\u8bbe\u8ba1\u7684\u57fa\u77f3\uff0c\u5b9e\u9645\u4e0a\uff0c\u5176\u4ed6\u539f\u5219\u90fd\u53ef\u4ee5\u770b\u4f5c\u662f\u5b9e\u73b0\u5f00\u95ed\u539f\u5219\u7684\u5de5\u5177\u548c\u624b\u6bb5\u3002\u610f\u601d\u5c31\u662f\uff1a\u8f6f\u4ef6\u5bf9\u6269\u5c55\u5e94\u8be5\u662f\u5f00\u653e\u7684\uff0c\u5bf9\u4fee\u6539\u662f\u5c01\u95ed\u7684\uff0c\u901a\u4fd7\u6765\u8bf4\u5c31\u662f\uff0c\u5f00\u53d1\u4e00\u4e2a\u8f6f\u4ef6\u65f6\uff0c\u5e94\u8be5\u5bf9\u5176\u8fdb\u884c\u529f\u80fd\u6269\u5c55\uff0c\u800c\u5728\u8fdb\u884c\u8fd9\u4e9b\u6269\u5c55\u65f6\uff0c\u4e0d\u9700\u8981\u5bf9\u539f\u6765\u7684\u7a0b\u5e8f\u8fdb\u884c\u4fee\u6539\u3002<\/p>\n<p>\u597d\u5904\u662f\uff1a\u8f6f\u4ef6\u53ef\u7528\u6027\u975e\u5e38\u7075\u6d3b\uff0c\u6269\u5c55\u6027\u5f3a\u3002\u9700\u8981\u65b0\u7684\u529f\u80fd\u65f6\uff0c\u53ef\u4ee5\u589e\u52a0\u65b0\u7684\u6a21\u5757\u6765\u6ee1\u8db3\u65b0\u9700\u6c42\u3002\u53e6\u5916\u7531\u4e8e\u539f\u6765\u7684\u6a21\u5757\u6ca1\u6709\u4fee\u6539\uff0c\u6240\u4ee5\u4e0d\u7528\u62c5\u5fc3\u7a33\u5b9a\u6027\u7684\u95ee\u9898\u3002<\/p>\n<h2 id=\"blogTitle5\">\u4e8c\u3001\u5355\u4e00\u804c\u8d23\u539f\u5219<\/h2>\n<p>Single-Responsibilitiy Principle\uff08SRP\uff09\uff1a\u5bf9\u4e00\u4e2a\u7c7b\u800c\u8a00\uff0c\u5e94\u8be5\u4ec5\u6709\u4e00\u4e2a\u5f15\u8d77\u5b83\u53d8\u5316\u7684\u539f\u56e0\u3002\u5982\u679c\u5b58\u5728\u591a\u4e8e\u4e00\u4e2a\u52a8\u673a\u53bb\u6539\u53d8\u4e00\u4e2a\u7c7b\uff0c\u90a3\u4e48\u8fd9\u4e2a\u7c7b\u5c31\u5177\u6709\u591a\u4e8e\u4e00\u4e2a\u7684\u804c\u8d23\uff0c\u5c31\u5e94\u8be5\u628a\u591a\u4f59\u7684\u804c\u8d23\u5206\u79bb\u51fa\u53bb\uff0c\u518d\u53bb\u521b\u5efa\u4e00\u4e9b\u7c7b\u6765\u5b8c\u6210\u6bcf\u4e00\u4e2a\u804c\u8d23\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff1a\u4e00\u4e2a\u4eba\u8eab\u517c\u6570\u804c\uff0c\u800c\u8fd9\u4e9b\u4e8b\u60c5\u76f8\u5173\u6027\u4e0d\u5927\uff0c\u751a\u81f3\u6709\u51b2\u7a81\uff0c\u90a3\u4ed6\u5c31\u65e0\u6cd5\u5f88\u597d\u7684\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u804c\u8d23\uff0c\u5e94\u8be5\u5206\u5230\u4e0d\u540c\u7684\u4eba\u8eab\u4e0a\u53bb\u505a\u3002<\/p>\n<p>\u5355\u4e00\u804c\u8d23\u539f\u5219\u662f\u5b9e\u73b0\u9ad8\u5185\u805a\u4f4e\u8026\u5408\u7684\u6700\u597d\u65b9\u6cd5\uff0c\u6ca1\u6709\u4e4b\u4e00\u3002<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img src=\"https:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre> 1 class CellPhone\uff1a\r\n 2   \r\n 3     def call\uff08string person\uff09\uff1a\r\n 4       \/\/\u6253\u7535\u8bdd\r\n 5       pass\r\n 6     def hangup\uff08\uff09\uff1a\r\n 7      \/\/\u6302\u65ad\u7535\u8bdd\r\n 8         pass\r\n 9 \r\n10     def sendMessage\uff08string person\uff09\uff1a\r\n11     \/\/\u53d1\u9001\u4fe1\u606f\r\n12         pass\r\n13     def receiveMessage():\r\n14     \/\/\u63a5\u53d7\u4fe1\u606f\r\n15         pass<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img src=\"https:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>\u4e0a\u9762\u7684\u624b\u673a\u7c7b\u867d\u7136\u7b26\u5408\u4eba\u4eec\u5bf9\u624b\u673a\u7684\u8ba4\u8bc6\uff0c\u4f46\u662f\u5b9e\u9645\u4e0a\u5374\u62e5\u6709\u4e24\u4e2a\u4e0d\u540c\u7684\u804c\u8d23\uff1a\u6253\u7535\u8bdd\u3001\u6302\u65ad\u7535\u8bdd\u548c\u53d1\u77ed\u4fe1\u3001\u63a5\u53d7\u4fe1\u606f\uff0c\u56e0\u6b64\u5f15\u8d77\u5b83\u53d8\u5316\u7684\u539f\u56e0\u5c31\u6709\u591a\u4e2a\uff0c\u662f\u6bd4\u8f83\u8106\u5f31\u7684\u8bbe\u8ba1\uff0c\u5e94\u8be5\u5c06\u4e24\u79cd\u884c\u4e3a\u5206\u79bb\u3002<\/p>\n<h2 id=\"blogTitle6\">\u4e09\u3001\u91cc\u6c0f\u4ee3\u6362\u539f\u5219<\/h2>\n<p>Liskov Substitution Principle\uff1a\u5b50\u7c7b\u53ef\u4ee5\u6269\u5c55\u7236\u7c7b\u7684\u529f\u80fd\uff0c\u4f46\u662f\u4e0d\u80fd\u6539\u53d8\u7236\u7c7b\u539f\u6709\u7684\u529f\u80fd\u3002<\/p>\n<p>\u5728\u7b2c\u4e00\u6761\u539f\u5219\u5f00\u653e\u5c01\u95ed\u539f\u5219\u4e2d\uff0c\u4e3b\u5f20\u201c\u62bd\u8c61\u201d\u548c\u201c\u591a\u6001\u201d\u3002\u7ef4\u6301\u8bbe\u8ba1\u7684\u5c01\u88c5\u6027\u201c\u62bd\u8c61\u201d\u662f\u8bed\u8a00\u63d0\u4f9b\u7684\u529f\u80fd\uff0c\u201c\u591a\u6001\u201d\u7531\u7ee7\u627f\u8bed\u610f\u5b9e\u73b0\u3002\u56e0\u6b64\u5982\u4f55\u53bb\u5ea6\u91cf\u7ee7\u627f\u5173\u7cfb\u4e2d\u7684\u8d28\u91cf\uff1f<\/p>\n<p>\u7b54\u6848\u662f\uff1a\u7ee7\u627f\u5fc5\u987b\u660e\u786e\u786e\u4fdd\u8d85\u7c7b\uff08\u7236\u7c7b\uff09\u6240\u62e5\u6709\u7684\u6027\u8d28\u5728\u5b50\u7c7b\u4e2d\u4ecd\u7136\u6210\u7acb\u3002<\/p>\n<p>\u5728\u9762\u5411\u5bf9\u8c61\u7684\u601d\u60f3\u4e2d\uff0c\u4e00\u4e2a\u5bf9\u8c61\u5c31\u662f\u4e00\u7ec4\u72b6\u6001\u548c\u4e00\u7cfb\u5217\u884c\u4e3a\u7684\u7ec4\u5408\u4f53\u3002\u72b6\u6001\u662f\u5bf9\u8c61\u7684\u5185\u5728\u7279\u6027\uff0c\u884c\u4e3a\u662f\u5bf9\u8c61\u7684\u5916\u5728\u7279\u6027\u3002LSP\u8868\u8ff0\u7684\u5c31\u662f\u5728\u540c\u4e00\u7ee7\u627f\u4f53\u7cfb\u4e2d\u7684\u961f\u5f62\u5e94\u8be5\u5177\u6709\u5171\u540c\u7684\u884c\u4e3a\u7279\u5f81\u3002<\/p>\n<div class=\"cnblogs_code\">\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img src=\"https:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<pre> 1 class bird\uff1a\r\n 2     color = ''\r\n 3     weight = ''\r\n 4     def eat():\r\n 5         pass\r\n 6     def fly():\r\n 7         print(\"fly\")\r\n 8         \r\n 9 class chicken(bird):\r\n10     def fly():\r\n11         print(\"can not fly\")<\/pre>\n<div class=\"cnblogs_code_toolbar\"><span class=\"cnblogs_code_copy\"><a title=\"\u590d\u5236\u4ee3\u7801\"><img src=\"https:\/\/common.cnblogs.com\/images\/copycode.gif\" alt=\"\u590d\u5236\u4ee3\u7801\" \/><\/a><\/span><\/div>\n<\/div>\n<p>\u5728\u4e0a\u8ff0\u4f8b\u5b50\u4e2d\uff0c\u7236\u7c7b\u4e5f\u5c31\u662f\u5bf9\u8c61\u9e1f\u6709\u4e24\u4e2a\u884c\u4e3a\u4e5f\u5c31\u662f\u65b9\u6cd5\uff1aeat()\u548cfly(),\u5728\u5b50\u7c7bchicken\u4e2d\u8fd9\u4e24\u4e2a\u884c\u4e3a\u4e5f\u5e94\u8be5\u6210\u7acb\uff0c\u4f46\u662f\u73b0\u5b9e\u4e2dchicken\u662f\u4e0d\u80fd\u98de\u7684\uff0c\u56e0\u6b64chicken\u4e2d\u7684fly()\u65b9\u6cd5\u8986\u76d6\u4e86\u7236\u7c7b\u4e2d\u7684\u65b9\u6cd5\u3002\u8fdd\u53cd\u4e86VSP\u3002<\/p>\n<h2 id=\"blogTitle7\">\u56db\u3001\u4f9d\u8d56\u5012\u7f6e\u539f\u5219<\/h2>\n<p>Dependence Inversion Principle\uff08DIP\uff09\uff1a\u662f\u4e00\u4e2a\u7c7b\u4e0e\u7c7b\u4e4b\u95f4\u7684\u8c03\u7528\u89c4\u5219\u3002\u8fd9\u91cc\u7684\u4f9d\u8d56\u5c31\u662f\u4ee3\u7801\u4e2d\u7684\u8026\u5408\u3002\u9ad8\u5c42\u6a21\u5757\u4e0d\u5e94\u8be5\u4f9d\u8d56\u5e95\u5c42\u6a21\u5757\uff0c\u4e8c\u8005\u90fd\u5e94\u8be5\u4f9d\u8d56\u5176\u62bd\u8c61\u4e86\uff1b\u62bd\u8c61\u4e0d\u4f9d\u8d56\u7ec6\u8282\uff1b\u7ec6\u8282\u5e94\u8be5\u4f9d\u8d56\u62bd\u8c61\u3002\u63a5\u53e3\u7f16\u7a0b\u3002<\/p>\n<p>\u4e3b\u8981\u601d\u60f3\u5c31\u662f\uff1a\u5982\u679c\u4e00\u4e2a\u7c7b\u4e2d\u7684\u4e00\u4e2a\u6210\u5458\u6216\u8005\u53c2\u6570\u6210\u4e3a\u4e00\u4e2a\u5177\u4f53\u7684\u7c7b\u578b\uff0c\u90a3\u4e48\u8fd9\u4e2a\u7c7b\u5c31\u4f9d\u8d56\u8fd9\u4e2a\u5177\u4f53\u7c7b\u578b\u3002\u5982\u679c\u5728\u4e00\u4e2a\u7ee7\u627f\u7ed3\u6784\u4e2d\uff0c\u4e0a\u5c42\u7c7b\u4e2d\u7684\u4e00\u4e2a\u6210\u5458\u6216\u8005\u53c2\u6570\u4e3a\u4e00\u4e2a\u4e0b\u5c42\u7c7b\u578b\uff0c\u90a3\u4e48\u5c31\u662f\u8fd9\u4e2a\u7ee7\u627f\u7ed3\u6784\u9ad8\u5c42\u4f9d\u8d56\u5e95\u5c42\uff0c\u5c31\u8981\u5c3d\u91cf\u9762\u5411\u62bd\u8c61\u6216\u8005\u63a5\u53e3\u7f16\u7a0b\u3002<\/p>\n<p>\u4e3e\u4f8b\uff1a\u5b58\u5728\u4e00\u4e2aDriver\u7c7b\uff0c\u6210\u5458\u4e3a\u4e00\u4e2aCar\u5bf9\u8c61\uff0c\u8fd8\u6709\u4e00\u4e2adriver()\u65b9\u6cd5\uff0cCar\u5bf9\u8c61\u4e2d\u6709\u4e24\u4e2a\u65b9\u6cd5start()\u4e0estop()\u3002\u663e\u7136Driver\u4f9d\u8d56Car\uff0c\u4e5f\u5c31\u662f\u8bf4Driver\u7c7b\u8c03\u7528\u4e86Car\u7c7b\u4e2d\u7684\u65b9\u6cd5\u3002\u4f46\u662f\u5f53\u589e\u52a0Driver\u7c7b\u5bf9\u4e8eBus\u7c7b\u7684\u652f\u6301\u65f6\uff08\u53f8\u673a\u6709\u9700\u8981\u5f00\u516c\u4ea4\u8f66\uff09\uff0c\u5c31\u5fc5\u987b\u66f4\u6539Driver\u4e2d\u7684\u4ee3\u7801\uff0c\u5c31\u7834\u574f\u4e86\u5f00\u653e\u5c01\u95ed\u539f\u5219\u3002\u6839\u672c\u539f\u56e0\u5728\u4e8e\u9ad8\u5c42\u7684\u7684Driver\u7c7b\u4e0e\u5e95\u5c42\u7684Car\u7c7b\u4ec5\u4ec5\u7684\u8026\u5408\u5728\u4e00\u8d77\u7684\u3002\u89e3\u51b3\u65b9\u6cd5\u4e4b\u4e00\u5c31\u662f\uff1a\u5bf9Car\u7c7b\u548cBus\u7c7b\u8fdb\u884c\u62bd\u8c61\uff0c\u5f15\u5165\u62bd\u8c61\u7c7bAutomoble\u3002\u800cCar\u548cBus\u5219\u662f\u5bf9Automobile\u7684\u6cdb\u5316\u3002<\/p>\n<p>\u7ecf\u8fc7\u8fd9\u6837\u7684\u6539\u9020\u53d1\u73b0\uff0c\u539f\u672c\u7684\u9ad8\u5c42\u4f9d\u8d56\u5e95\u5c42\uff0c\u53d8\u6210\u4e86\u9ad8\u5c42\u4e0e\u5e95\u5c42\u540c\u65f6\u4f9d\u8d56\u62bd\u8c61\u3002\u8fd9\u5c31\u662f\u4f9d\u8d56\u5012\u8f6c\u539f\u5219\u7684\u672c\u8d28\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2 id=\"blogTitle8\">\u4e94\u3001\u63a5\u53e3\u9694\u79bb\u539f\u5219<\/h2>\n<p>\u63a5\u53e3\u9694\u79bb\u539f\u5219\uff08Interface Segregation Principle\uff09\uff1a\u7528\u4e8e\u6070\u5f53\u7684\u5212\u5206\u89d2\u8272\u548c\u63a5\u53e3\uff0c\u5177\u6709\u4e24\u79cd\u542b\u4e49\uff1a1\u3001\u7528\u6237\u4e0d\u5e94\u8be5\u4f9d\u8d56\u5b83\u4e0d\u9700\u8981\u7684\u501f\u53e3\uff1b2\u3001\u7c7b\u95f4\u7684\u4f9d\u8d56\u5173\u7cfb\u5e94\u8be5\u5efa\u7acb\u5728\u6700\u5c0f\u7684\u7684\u63a5\u53e3\u4e0a\u3002<\/p>\n<p>\u5c06\u8fd9\u4e24\u4e2a\u5b9a\u4e49\u6982\u62ec\u4e3a\u4e00\u53e5\u8bdd\uff1a\u5efa\u7acb\u5355\u4e00\u63a5\u53e3\uff0c\u4ee3\u66ff\u5e9e\u5927\u81c3\u80bf\u7684\u63a5\u53e3\u3002\u901a\u4fd7\u6765\u8bf4\u5c31\u662f\uff1a\u63a5\u53e3\u5c3d\u91cf\u7ec6\u5316\uff0c\u540c\u65f6\u4fdd\u8bc1\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\u5c3d\u91cf\u7684\u5c11\u3002\u4e00\u4e2a\u63a5\u53e3\u4e2d\u5305\u542b\u592a\u591a\u7684\u884c\u4e3a\u65f6\uff0c\u4f1a\u5bfc\u81f4\u5b83\u4eec\u4e0e\u5ba2\u6237\u7aef\u7684\u4e0d\u6b63\u5e38\u4f9d\u8d56\u5173\u7cfb\uff0c\u8981\u505a\u7684\u5c31\u662f\u5206\u79bb\u63a5\u53e3\uff0c\u4ece\u800c\u5b9e\u73b0\u89e3\u8026\u3002<\/p>\n<p>\u56de\u5230\u4e0a\u8ff0\u7684\u5355\u4e00\u804c\u8d23\u539f\u5219\uff0c\u8981\u6c42\u884c\u4e3a\u5206\u79bb\u63a5\u53e3\u63a5\u53e3\u7ec6\u5316\uff0c\u611f\u89c9\u6709\u4e9b\u76f8\u540c\u3002\u4f46\u5b9e\u9645\u4e0a\uff0c\u5355\u4e00\u804c\u8d23\u539f\u5219\u8981\u6c42\u7c7b\u4e0e\u63a5\u53e3\u7684\u804c\u8d23\u5355\u4e00\uff0c\u6ce8\u91cd\u7684\u662f\u804c\u8d23\uff0c\u6ca1\u6709\u8981\u6c42\u63a5\u53e3\u5c3d\u91cf\u7684\u5c11\u3002<\/p>\n<p>\u5728\u63a5\u53e3\u9694\u79bb\u539f\u5219\u4e2d\uff0c\u8981\u6c42\u5c3d\u91cf\u4f7f\u7528\u591a\u4e2a\u4e13\u95e8\u7684\u63a5\u53e3\u3002\u4e13\u95e8\u7684\u63a5\u53e3\u4e5f\u5c31\u662f\u63d0\u4f9b\u7ed9\u591a\u4e2a\u6a21\u5757\u7684\u63a5\u53e3\u3002\u63d0\u4f9b\u7ed9\u51e0\u4e2a\u6a21\u5757\u5c31\u5e94\u8be5\u6709\u51e0\u4e2a\u63a5\u53e3\uff0c\u800c\u4e0d\u662f\u5efa\u7acb\u4e00\u4e2a\u81c3\u80bf\u5e9e\u5927\u7684\u63a5\u53e3\uff0c\u6240\u6709\u7684\u6a21\u5757\u90fd\u53ef\u4ee5\u8bbf\u95ee\u3002<\/p>\n<p>\u4f46\u662f\u63a5\u53e3\u7684\u8bbe\u8ba1\u662f\u6709\u9650\u5ea6\u7684\u3002\u63a5\u53e3\u7684\u8bbe\u8ba1\u7c92\u5ea6\u8d8a\u5c0f\u7cfb\u7edf\u8d8a\u7075\u6d3b\uff0c\u8fd9\u662f\u4e8b\u5b9e\uff0c\u4f46\u662f\u63a5\u53e3\u592a\u591a\u8fd9\u4e5f\u5c31\u4f7f\u5f97\u7ed3\u6784\u590d\u6742\uff0c\u7ef4\u62a4\u96be\u5ea6\u5927\u3002\u56e0\u6b64\u5b9e\u9645\u4e2d\uff0c\u600e\u6837\u628a\u63e1\u5c31\u9760\u5f00\u53d1\u7684\u7ecf\u9a8c\u548c\u5e38\u8bc6\u4e86\u3002<\/p>\n<h2 id=\"blogTitle9\">\u516d\u3001\u8fea\u7c73\u7279\u539f\u5219<\/h2>\n<p>Law of Demeter\uff08\u6700\u5c0f\u77e5\u8bc6\u539f\u5219\uff09\uff1a\u4e00\u4e2a\u5bf9\u8c61\u5e94\u8be5\u5bf9\u5176\u4ed6\u5bf9\u8c61\u6709\u6700\u5c11\u7684\u4e86\u89e3\u3002\u901a\u4fd7\u6765\u8bf4\u5c31\u662f\uff0c\u4e00\u4e2a\u7c7b\u5bf9\u81ea\u5df1\u9700\u8981\u8026\u5408\u6216\u8005\u8c03\u7528\u7684\u7c7b\u77e5\u9053\u7684\u6700\u5c11\uff0c\u4f60\u7c7b\u5185\u90e8\u600e\u4e48\u590d\u6742\uff0c\u6211\u4e0d\u7ba1\uff0c\u90a3\u662f\u4f60\u7684\u4e8b\uff0c\u6211\u53ea\u77e5\u9053\u4f60\u6709\u90a3\u4e48\u591a\u516c\u7528\u7684\u65b9\u6cd5\uff0c\u6211\u80fd\u8c03\u7528\u3002<\/p>\n<p>\u8fea\u7c73\u7279\u539f\u5219\u4e0d\u5e0c\u671b\u7c7b\u4e0e\u7c7b\u4e4b\u95f4\u5efa\u7acb\u76f4\u63a5\u7684\u63a5\u89e6\u3002\u5982\u679c\u771f\u7684\u9700\u8981\u6709\u8054\u7cfb\uff0c\u90a3\u4e48\u5c31\u901a\u8fc7\u5b83\u4eec\u7684\u53cb\u5143\u7c7b\u6765\u4f20\u8fbe\u3002\u4e3e\u4f8b\u6765\u8bf4\uff1a\u4f60\u9700\u8981\u4e70\u623f\u5b50\u4e86\uff0c\u73b0\u5728\u5b58\u5728\u4e09\u5ea7\u5408\u9002\u7684\u697c\u76d8A\uff0cB\uff0cC\uff0c\u4f46\u662f\u4f60\u4e0d\u5fc5\u76f4\u63a5\u53bb\u697c\u76d8\u4e70\u697c\uff0c\u800c\u662f\u5728\u552e\u697c\u5904\u53bb\u4e86\u89e3\u60c5\u51b5\u3002\u8fd9\u6837\u5c31\u51cf\u5c11\u4e86\u4f60\uff08\u8d2d\u623f\u8005\uff09\u4e0e\u697c\u76d8\u4e24\u4e2a\u7c7b\u4e4b\u95f4\u8026\u5408\u3002<\/p>\n<p>\u4f46\u662f\u5e94\u7528\u8fea\u7c73\u7279\u539f\u5219\u5f88\u53ef\u80fd\u4f1a\u9020\u6210\u4e00\u4e2a\u540e\u679c\uff1a\u7cfb\u7edf\u4f1a\u5b58\u5728\u5927\u91cf\u7684\u4e2d\u4ecb\u7c7b\uff0c\u8fd9\u4e9b\u7c7b\uff08\u5982\u4e0a\u9762\u7684\u552e\u697c\u5904\u7c7b\uff09\u4e4b\u6240\u4ee5\u5b58\u5728\u662f\u4e3a\u4e86\u4f20\u9012\u7c7b\u4e4b\u95f4\u7684\u76f8\u4e92\u8c03\u7528\u5173\u7cfb\uff0c\u8fd9\u5c31\u4e00\u5b9a\u4f1a\u7a0b\u5ea6\u4e0a\u589e\u52a0\u4e86\u7cfb\u7edf\u7684\u590d\u6742\u5ea6\u3002<\/p>\n<p>\u8fea\u7c73\u7279\u539f\u5219\u6838\u5fc3\u89c2\u5ff5\u5c31\u662f\uff1a\u7c7b\u95f4\u89e3\u8026\uff0c\u5f31\u8026\u5408\u3002<\/p>\n<p>\u539f\u6587\u5730\u5740 \uff1ahttps:\/\/www.cnblogs.com\/welan\/p\/9005019.html<\/p>\n<p>\u6e90\u7801\u5730\u5740:<a href=\"https:\/\/github.com\/weilanhanf\/PythonDesignPatterns\">https:\/\/github.com\/weilanhanf\/PythonDesignPatterns<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u521b\u5efa\u578b\uff1a \u5355\u4f8b\u6a21\u5f0f\u3001\u5de5\u5382\u6a21\u5f0f\u3001\u62bd\u8c61\u5de5\u5382\u6a21\u5f0f\u3001\u539f\u578b\u6a21\u5f0f\u3001\u5efa\u9020\u8005\u6a21\u5f0f\uff1b \u4e8c\u3001\u7ed3\u6784\u578b\uff1a \u4ee3\u7406\u6a21\u5f0f,\u88c5\u9970\u5668\u6a21\u5f0f\u3001\u9002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":157,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[34],"tags":[35],"_links":{"self":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/692"}],"collection":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=692"}],"version-history":[{"count":3,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/692\/revisions"}],"predecessor-version":[{"id":695,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/692\/revisions\/695"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/media\/157"}],"wp:attachment":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=692"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}