{"id":213,"date":"2020-10-05T08:01:21","date_gmt":"2020-10-05T08:01:21","guid":{"rendered":"https:\/\/turtleflyblog.com\/?p=213"},"modified":"2022-02-28T09:48:12","modified_gmt":"2022-02-28T09:48:12","slug":"solid-isp-2","status":"publish","type":"post","link":"https:\/\/turtleflyblog.com\/zh\/2020\/10\/05\/solid-isp-2\/","title":{"rendered":"SOLID \u8a2d\u8a08\u539f\u5247 – \u4ecb\u9762\u9694\u96e2\u539f\u5247\uff08ISP\uff09"},"content":{"rendered":"\n
\u672c\u6587\u4ecb\u7d39S.O.L.I.D\u539f\u5247\u4e2d\u7684\u4ecb\u9762\u9694\u96e2\u539f\u5247<\/strong>(Interface Segregation Principle\uff0c\u7e2e\u5beb\u70baISP)\u3002<\/p>\n\n\n\n \u8a72\u539f\u5247\u4e3b\u65e8\u70ba\u8207\u5176\u5efa\u9020\u4e00\u500b\u9f90\u5927\u64c1\u816b\u7684\u4ecb\u9762(interface)\uff0c\u4e0d\u5982\u6539\u6210\u70ba\u6578\u500b\u5c0f\u578b\u4ecb\u9762\uff0c\u65b9\u4fbf\u958b\u8026\u5408\u548c\u91cd\u69cb\u3002<\/p>\n\n\n\n Too many is better than too few<\/em><\/p>\n\n\n\n \u8209\u500b\u4f8b\u5b50\u4f86\u8aaa\uff0c\u4f60\u6709[Animal]\u4ecb\u9762\uff0c\u52d5\u7269\u6703\u505a<\/p>\n\n\n\n [\u5403]\uff0c[\u52d5]\uff0c[\u7761]<\/p>\n\n\n\n \u5716\u4e0aIAnimal\u4ecb\u9762\u5305\u542b\u4e09\u500b\u52d5\u4f5c\u53ef\u4f5c\u7528\u65bc\u6240\u6709\u52d5\u7269\u4f8b\u5982\u718a\uff0c\u864e\uff0c\u8c61\u7b49\u7b49\u3002\u4f46\u5982\u679c\u6709\u4e00\u500bPlant(\u690d\u7269)\u985e\u5225\u8981\u7e7c\u627f\u6b64IAnimal\u4ecb\u9762\uff0c\u5247IAnimal\u5927\u90e8\u4efd\u7684\u884c\u70ba\u4e26\u4e0d\u7b26\u5408Plant\uff0c\u6240\u4ee5\u4e26\u4e0d\u9069\u7528\u3002<\/p>\n\n\n\n \u8a66\u60f3\u6211\u5011\u63db\u6210\u53e6\u5916\u4e00\u500b\u60c5\u5883\u3002\u6211\u5011\u5c07IAnimal\u62c6\u6210\u4e09\u500b\u5c0f\u578b\u4ecb\u9762(eat, move, sleep)\u3002\u690d\u7269(Plant)\u96d6\u7136\u4e0d\u6703[\u52d5]\u4e5f\u4e0d\u6703[\u7761]\uff0c\u4f46\u6703\u6d88\u8017\u80fd\u6e90\u548c\u6392\u653e\u6c27\u6c23\uff0c\u6240\u4ee5\u5403(eat)\u52d5\u4f5c\u662f\u53ef\u4ee5\u4f5c\u7528\u65bc[Plant]\u690d\u7269\u985e\u5225\u4e0a\u7684\u3002<\/p>\n\n\n\n \u6b64\u4f8b\u5b50\u986f\u793a\u8f15\u5c0f\u578b\u7684\u4ecb\u9762\u6bd4\u8d77\u5de8\u578b\u7684\u4ecb\u9762(interface)\u66f4\u5177\u6709\u64f4\u5145\u6027\u548c\u53ef\u7528\u6027\u3002\u53cd\u89c0\u5982\u679c[Plant]\u7e7c\u627f\u4e86IAnimal\u4ecb\u9762\u9700\u8981\u5be6\u4f5c\u592a\u591a\u6c92\u6709\u5fc5\u8981\u7684\u65b9\u6cd5\uff0c\u4e14\u6703\u9700\u8981\u4fee\u6539\u5f88\u591a\u7684\u7a0b\u5f0f\u78bc\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" \u672c\u6587\u4ecb\u7d39S.O.L.I.D\u539f\u5247\u4e2d\u7684\u4ecb\u9762\u9694\u96e2\u539f\u5247(Interface Segregation Principle\uff0c\u7e2e\u5beb\u70baISP)\u3002 \u8a72\u539f\u5247\u4e3b\u65e8\u70ba\u8207\u5176\u5efa\u9020\u4e00\u500b\u9f90\u5927\u64c1\u816b\u7684\u4ecb\u9762(interface)\uff0c\u4e0d\u5982\u6539\u6210\u70ba\u6578\u500b\u5c0f\u578b\u4ecb\u9762\uff0c\u65b9\u4fbf\u958b\u8026\u5408\u548c\u91cd\u69cb\u3002 Too many is better than too few \u8209\u500b\u4f8b\u5b50\u4f86\u8aaa\uff0c\u4f60\u6709[Animal]\u4ecb\u9762\uff0c\u52d5\u7269\u6703\u505a [\u5403]\uff0c[\u52d5]\uff0c[\u7761] \u5716\u4e0aIAnimal\u4ecb\u9762\u5305\u542b\u4e09\u500b\u52d5\u4f5c\u53ef\u4f5c\u7528\u65bc\u6240\u6709\u52d5\u7269\u4f8b\u5982\u718a\uff0c\u864e\uff0c\u8c61\u7b49\u7b49\u3002\u4f46\u5982\u679c\u6709\u4e00\u500bPlant(\u690d\u7269)\u985e\u5225\u8981\u7e7c\u627f\u6b64IAnimal\u4ecb\u9762\uff0c\u5247IAnimal\u5927\u90e8\u4efd\u7684\u884c\u70ba\u4e26\u4e0d\u7b26\u5408Plant\uff0c\u6240\u4ee5\u4e26\u4e0d\u9069\u7528\u3002 \u8a66\u60f3\u6211\u5011\u63db\u6210\u53e6\u5916\u4e00\u500b\u60c5\u5883\u3002\u6211\u5011\u5c07IAnimal\u62c6\u6210\u4e09\u500b\u5c0f\u578b\u4ecb\u9762(eat, move, sleep)\u3002\u690d\u7269(Plant)\u96d6\u7136\u4e0d\u6703[\u52d5]\u4e5f\u4e0d\u6703[\u7761]\uff0c\u4f46\u6703\u6d88\u8017\u80fd\u6e90\u548c\u6392\u653e\u6c27\u6c23\uff0c\u6240\u4ee5\u5403(eat)\u52d5\u4f5c\u662f\u53ef\u4ee5\u4f5c\u7528\u65bc[Plant]\u690d\u7269\u985e\u5225\u4e0a\u7684\u3002 \u6b64\u4f8b\u5b50\u986f\u793a\u8f15\u5c0f\u578b\u7684\u4ecb\u9762\u6bd4\u8d77\u5de8\u578b\u7684\u4ecb\u9762(interface)\u66f4\u5177\u6709\u64f4\u5145\u6027\u548c\u53ef\u7528\u6027\u3002\u53cd\u89c0\u5982\u679c[Plant]\u7e7c\u627f\u4e86IAnimal\u4ecb\u9762\u9700\u8981\u5be6\u4f5c\u592a\u591a\u6c92\u6709\u5fc5\u8981\u7684\u65b9\u6cd5\uff0c\u4e14\u6703\u9700\u8981\u4fee\u6539\u5f88\u591a\u7684\u7a0b\u5f0f\u78bc\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[35],"tags":[],"class_list":["post-213","post","type-post","status-publish","format-standard","hentry","category--zh"],"yoast_head":"\n<\/figure>\n\n\n\n
<\/figure>\n\n\n\n