{"id":817,"date":"2020-10-29T18:00:02","date_gmt":"2020-10-29T10:00:02","guid":{"rendered":"https:\/\/t.n-years.com\/?p=817"},"modified":"2021-03-26T16:09:18","modified_gmt":"2021-03-26T08:09:18","slug":"%e7%bf%bb%e8%af%91%e5%a6%82%e4%bd%95%e8%ae%be%e8%ae%a1%e8%89%af%e5%a5%bd%e7%9a%84-api-%e5%8f%8a%e5%85%b6%e9%87%8d%e8%a6%81%e6%80%a7","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=817","title":{"rendered":"[\u7ffb\u8bd1]\u5982\u4f55\u8bbe\u8ba1\u597d\u7684 API \u53ca\u5176\u91cd\u8981\u6027"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u539f\u94fe\u63a5\uff1a<a href=\"\"><\/a><a href=\"http:\/\/fwdinnovations.net\/whitepaper\/APIDesign.pdf\">How to Design a Good API and Why it Matters<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4f5c\u8005\u7b80\u4ecb\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/zh.wikipedia.org\/wiki\/%E7%B4%84%E6%9B%B8%E4%BA%9E%C2%B7%E5%B8%83%E6%B4%9B%E5%85%8B\">\u7ea6\u4e66\u4e9a\u00b7\u5e03\u6d1b\u514b<\/a>\uff0c\u66fe\u62c5\u4efbGoogle\u7684\u9996\u5e2dJava\u67b6\u6784\u5e08\uff08Chief Java Architect\uff09,\u300a<em>Effective Java<\/em>\u300b\u4f5c\u8005\uff0c\u300a<em>Java Concurrency In Practice<\/em>\u300b\u5171\u540c\u4f5c\u8005\uff0c2004\u5e7412\u6708\uff0c\u300aJava\u5f00\u53d1\u8005\u6742\u5fd7\u300b\uff08Java Developer's Journal\uff09\u5c06\u4ed6\u5217\u4e3a\u4e16\u754c\u4e0a\u6700\u9876\u5c16\u7684\u56db\u5341\u540d\u8f6f\u4ef6\u4eba\u7269\u4e4b\u4e00\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e3a\u4ec0\u4e48 API \u8bbe\u8ba1\u5982\u6b64\u91cd\u8981<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>API \u53ef\u4ee5\u6210\u4e3a\u516c\u53f8\u6700\u5927\u7684\u8d44\u4ea7\uff1a<ul><li>\u5ba2\u6237\u6295\u8d44\u5de8\u5927\uff1a\u8d2d\u4e70\u3001\u7f16\u5199\u3001\u5b66\u4e60<\/li><li>\u505c\u6b62\u4f7f\u7528 API \u7684\u4ee3\u4ef7\u53ef\u80fd\u4f1a\u8ba9\u4eba\u671b\u800c\u5374\u6b65<\/li><li>\u6210\u529f\u7684\u516c\u5f00API\u53ef\u4ee5\u6293\u4f4f\u7528\u6237<\/li><\/ul><\/li><li>\u4e5f\u53ef\u80fd\u662f\u516c\u53f8\u6700\u5927\u7684\u8d1f\u503a\u4e4b\u4e00<ul><li>\u7cdf\u7cd5\u7684 API \u4f1a\u5bfc\u81f4\u65e0\u4f11\u6b62\u7684\u7535\u8bdd\u652f\u6301<\/li><\/ul><\/li><li>\u516c\u5f00 API \u6c38\u8fdc\u5b58\u5728 - \u53ea\u6709\u4e00\u6b21\u673a\u4f1a\u628a\u5b83\u5199\u6b63\u786e<\/li><li>\u53ea\u8981\u4f60\u5f00\u59cb\u7f16\u7a0b\uff0c\u4f60\u5c31\u662f API \u8bbe\u8ba1\u5e08<ul><li>\u597d\u7684\u4ee3\u7801\u662f\u6a21\u5757\u5316\u7684 - \u6bcf\u4e2a\u6a21\u5757\u90fd\u6709 API<\/li><\/ul><\/li><li>\u6709\u7528\u7684\u6a21\u5757\u5f80\u5f80\u4f1a\u88ab\u91cd\u7528<ul><li>\u6a21\u5757\u4e00\u65e6\u88ab\u4f7f\u7528\uff0c\u5c31\u4e0d\u80fd\u968f\u610f\u4fee\u6539API<\/li><li>\u4f18\u79c0\u7684\u53ef\u91cd\u7528\u6a21\u5757\u662f\u516c\u53f8\u8d44\u4ea7<\/li><\/ul><\/li><li>\u4ece API \u7684\u89d2\u5ea6\u8003\u8651\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u8d28\u91cf<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f18\u79c0 API \u7684\u7279\u5f81\uff1a<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6613\u4e8e\u5b66\u4e60<\/li><li>\u6613\u4e8e\u4f7f\u7528\uff0c\u5373\u4f7f\u5728\u6ca1\u6709\u6587\u6863\u7684\u60c5\u51b5\u4e0b<\/li><li>\u96be\u4ee5\u8bef\u7528<\/li><li>\u6613\u4e8e\u9605\u8bfb\u548c\u7ef4\u62a4<\/li><li>\u5145\u5206\u6ee1\u8db3\u9700\u6c42<\/li><li>\u6613\u4e8e\u6269\u5c55<\/li><li>\u9002\u5408\u4f7f\u7528\u8005\u7684\u89c6\u89d2\uff08Appropriate to audience)<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5927\u7eb2:<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4e00\u3001API \u8bbe\u8ba1\u8fc7\u7a0b<\/li><li>\u4e8c\u3001\u4e00\u822c\u539f\u5219<\/li><li>\u4e09\u3001\u7c7b\u7684\u8bbe\u8ba1<\/li><li>\u56db\u3001\u65b9\u6cd5\u8bbe\u8ba1<\/li><li>\u4e94\u3001\u5f02\u5e38\u8bbe\u8ba1<\/li><li>\u516d\u3001\u91cd\u6784 API \u8bbe\u8ba1<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e00\u3001API \u8bbe\u8ba1\u8fc7\u7a0b<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1.1 \u6536\u96c6\u9700\u6c42- \u5e76\u5408\u7406\u6000\u7591<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u901a\u5e38\u4f60\u4f1a\u5f97\u5230\u5efa\u8bae\u7684\u89e3\u51b3\u65b9\u6848<ul><li>\u53ef\u80fd\u5b58\u5728\u66f4\u597d\u7684\u89e3\u51b3\u65b9\u6848<\/li><\/ul><\/li><li>\u4f60\u7684\u5de5\u4f5c\u662f\u63d0\u70bc\u771f\u5b9e\u7684\u9700\u6c42<ul><li>\u5e94\u8be5\u4f7f\u7528 <strong><em>Use-Cases<\/em><\/strong>\uff08\u8fd9\u6837\u505a\u975e\u5e38\u597d\uff09<\/li><\/ul><\/li><li>\u66f4\u901a\u7528\u7684\u903b\u8f91\u53ef\u4ee5\u8ba9\u5de5\u4f5c\u66f4\u8f7b\u677e\u548c\u66f4\u6709\u610f\u4e49<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">1.2 \u4ece\u7b80\u77ed\u6e05\u5355\u5f00\u59cb - 1\u9875\u5c31\u591f<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u8fd9\u4e2a\u9636\u6bb5\uff0c\u654f\u6377\u80dc\u8fc7\u5b8c\u6574<\/li><li>\u8ba9\u5c3d\u53ef\u80fd\u591a\u7684\u4eba\u77e5\u9053<ul><li>\u542c\u53d6\u4ed6\u4eec\u7684\u610f\u89c1\u5e76\u8ba4\u771f\u5bf9\u5f85<\/li><\/ul><\/li><li>\u5982\u679c\u4fdd\u6301\u8bbe\u8ba1\u6587\u6863\u975e\u5e38\u7b80\u77ed\uff0c\u4fee\u6539\u5c31\u975e\u5e38\u5bb9\u6613<\/li><li>\u5f53\u4f60\u6709\u4fe1\u5fc3\u65f6\uff0c\u8865\u5145\u66f4\u591a\u7ec6\u8282<ul><li>\u8fd9\u5fc5\u7136\u6d89\u53ca\u7f16\u7801<\/li><\/ul><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">1.3 \u5c3d\u65e9\u7f16\u5199 API<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5728\u5b9e\u73b0\u524d\u5f00\u59cb\u7f16\u5199 API<ul><li>\u8282\u7701\u90a3\u4e9b\u4f1a\u88ab\u4f60\u629b\u5f03\u7684\u5b9e\u73b0<\/li><\/ul><\/li><li>\u5728\u6b63\u5f0f\u660e\u786e\u524d\u5f00\u59cb<ul><li>\u8282\u7701\u4f1a\u88ab\u4f60\u629b\u5f03\u7684 API \u63cf\u8ff0<\/li><\/ul><\/li><li>\u8865\u5145\u7ec6\u8282\u540e\u6301\u7eed\u7f16\u5199<ul><li>\u907f\u514d\u610f\u5916<\/li><li><strong>\u4ee3\u7801\u4f5c\u4e3a\u793a\u4f8b\u3001\u5355\u5143\u6d4b\u8bd5\u800c\u5b58\u5728<\/strong><\/li><\/ul><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">1.4 \u7f16\u5199 SPI \u66f4\u91cd\u8981<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>Service Provider Interface\uff08SPI\uff09<ul><li>\u63d2\u4ef6\u63a5\u53e3\u652f\u6301\u591a\u79cd\u5b9e\u73b0<\/li><li>\u793a\u4f8b\uff1aJava Cryptography Extension (JCE)<\/li><\/ul><\/li><li>\u5728\u53d1\u5e03\u4e4b\u524d\u7f16\u5199\u591a\u4e2a\u63d2\u4ef6<ul><li>\u5982\u679c\u4f60\u5199\u4e00\u4e2a\uff0c\u5b83\u5f88\u6709\u53ef\u80fd\u4e0d\u652f\u6301\u5176\u4ed6\u7684(\u4e0d\u597d\u7684\u5b9e\u73b0)<\/li><li>\u5982\u679c\u4f60\u5199\u4e24\u4e2a\uff0c\u5b83\u5c06\u8270\u96be\u7684\u652f\u6301\u66f4\u591a<\/li><li>\u5982\u679c\u4f60\u5199\u4e09\u4e2a\uff0c\u5c31\u80fd\u5f88\u597d\u7684\u5de5\u4f5c\uff08\u8fd9\u6837\u505a\u975e\u5e38\u597d\uff09<\/li><\/ul><\/li><li>\u5a01\u5c14\u00b7\u8d21\u57f9\u5179\u79f0\u4e4b\u4e3a\u201c\u4e09\u7684\u89c4\u5219\u201d\uff08\u300a\u4e8c\u624b\u7a0b\u5e8f\u9500\u552e\u5458\u7684\u81ea\u767d\u300b\uff0c\u57f9\u751f\u6559\u80b2\u51fa\u7248\u96c6\u56e2\uff0c1995\uff09<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">1.5 \u4fdd\u6301\u73b0\u5b9e\u7684\u671f\u671b\uff08<strong>Maintain Realistic Expectations<\/strong>\uff0c\u56de\u5230\u73b0\u5b9e\u4e16\u754c\uff1f\uff09<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5927\u591a\u6570API\u8bbe\u8ba1\u90fd\u662f\u8fc7\u7ea6\u675f\u7684<ul><li>\u4f60\u4e0d\u53ef\u80fd\u53d6\u60a6\u6240\u6709\u4eba<\/li><li>\u7ed3\u679c\u53ef\u80fd\u662f\u8ba9\u6bcf\u4e2a\u4eba\u90fd\u4e0d\u9ad8\u5174(Aim to displease everyone equally?)<\/li><\/ul><\/li><li>\u671f\u671b\u4f1a\u72af\u9519\u8bef\uff08Expect to make mistakes\uff09<ul><li>\u5b9e\u9645\u4f7f\u7528\u4e0d\u4e45\u5c31\u4f1a\u88ab\u6dd8\u6c70<\/li><li>\u671f\u671b\u6539\u8fdb API<\/li><\/ul><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e8c\u3001\u4e00\u822c\u539f\u5219<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">2.1 API \u5e94\u8be5\u53ea\u505a\u4e00\u4ef6\u4e8b\uff0c\u4e14\u628a\u5b83\u505a\u597d<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u529f\u80fd\u5e94\u8be5\u6613\u4e8e\u89e3\u91ca<ul><li>\u5982\u679c\u547d\u540d\u5f88\u56f0\u96be\uff0c\u8fd9\u901a\u5e38\u662f\u4e2a\u574f\u5146\u5934<\/li><li>\u597d\u7684\u540d\u5b57\u53ef\u4ee5\u9a71\u52a8\u5f00\u53d1<\/li><li>\u6613\u4e8e\u62c6\u5206\u548c\u5408\u5e76\u6a21\u5757<\/li><\/ul><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2.2 API \u5e94\u8be5\u5c3d\u53ef\u80fd\u5c0f\uff0c\u4e14\u4e0d\u80fd\u518d\u5c0f<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>API \u5e94\u8be5\u6ee1\u8db3\u5b83\u7684\u9700\u6c42<\/li><li><strong>\u5f53 API \u4e0d\u53ef\u9760\u65f6\uff0c\u5c31\u5e9f\u5f03<\/strong>\uff08When in doubt leave it out\uff09<ul><li>\u529f\u80fd\u3001\u7c7b\u3001\u65b9\u6cd5\u3001\u53c2\u6570\uff0c\u7b49\u7b49<\/li><li><strong>\u4f60\u53ef\u4ee5\u6dfb\u52a0\uff0c\u4f46\u6c38\u8fdc\u4e0d\u80fd\u5220\u9664<\/strong><\/li><\/ul><\/li><li>\u6982\u5ff5\u6743\u91cd\u6bd4\u4e3b\u4f53\u91cd\u8981<\/li><li>\u627e\u5230\u9ad8\u6027\u4ef7\u6bd4\u7684\u5b9e\u73b0\uff08Look for a good power-to-weight ratio\uff09\uff1f<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2.3 \u5b9e\u73b0\u4e0d\u5e94\u5f71\u54cd API<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b9e\u73b0\u7ec6\u8282<ul><li>\u6df7\u6dc6\u7528\u6237<\/li><li>\u7981\u6b62\u968f\u4fbf\u6539\u53d8\u5b9e\u73b0<\/li><\/ul><\/li><li>\u4e86\u89e3\u5b9e\u73b0\u7ec6\u8282\u662f\u4ec0\u4e48<ul><li>\u4e0d\u8981\u8fc7\u5ea6\u6307\u5b9a\u65b9\u6cd5\u7684\u884c\u4e3a\uff0c\u6bd4\u5982 \u4e0d\u8981\u5236\u5b9a \u54c8\u5e0c\u51fd\u6570<\/li><li>\u6240\u6709\u7684\u8c03\u6574\u53c2\u6570\u90fd\u662f\u53ef\u7591\u7684<\/li><\/ul><\/li><li>\u4e0d\u8981\u8ba9\u5b9e\u73b0\u7ec6\u8282\u6cc4\u9732\u5230 API<ul><li>\u78c1\u76d8\u548c\u5728\u7ebf\u683c\u5f0f\uff0c\u4f8b\u5916\uff08On-disk and on-the-wire formats, exceptions\uff1f\uff09<\/li><\/ul><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2.4 \u6700\u5c0f\u5316\u4e00\u5207\u7684\u53ef\u8bbf\u95ee\u6027<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u8ba9\u7c7b\u3001\u6210\u5458\u53d8\u91cf\u5c3d\u53ef\u80fd\u79c1\u6709<\/li><li>\u516c\u5f00\u7684\u7c7b\u4e0d\u8981\u6709\u516c\u5f00\u7684\u7c7b\u6210\u5458\uff08\u5e38\u91cf\u9664\u5916\uff09<\/li><li>\u6700\u5927\u7a0b\u5ea6\u4fe1\u606f\u9690\u85cf\uff08\u7cfb\u7edf\u7684\u5c40\u90e8\u8bbe\u8ba1\u7b80\u5316\uff09<\/li><li>\u5141\u8bb8\u6a21\u5757\u72ec\u7acb\u4f7f\u7528\uff0c\u88ab\u7406\u89e3\uff0c\u6784\u5efa\uff0c\u6d4b\u8bd5\u548c\u8c03\u8bd5<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2.5 \u547d\u540d\u7684\u91cd\u8981\u6027 - API\u5c31\u662f\u4e00\u79cd\u5fae\u578b\u8bed\u8a00<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u540d\u79f0\u5e94\u8be5\u6700\u5927\u7a0b\u5ea6\u7684\u81ea\u89e3\u91ca<ul><li>\u907f\u514d\u542b\u7cca\u7684\u7f29\u5199<\/li><\/ul><\/li><li>\u4fdd\u6301\u4e00\u81f4\u2014\u2014 \u540c\u4e00\u8bcd\u8868\u793a\u540c\u4e00\u4e8b\u7269<ul><li>\u5e73\u53f0\u4e0a\u7684\u6240\u6709 API<\/li><\/ul><\/li><li>\u6709\u89c4\u5f8b\u7684\u2014\u2014\u529b\u6c42\u76f8\u4f3c<\/li><li>\u4ee3\u7801\u8bfb\u8d77\u6765\u5e94\u8be5\u50cf\u6563\u6587<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>if (car.speed() > 2 * SPEED_LIMIT) \n      generateAlert(\"Watch out for cops!\");<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2.6 \u6587\u6863\u7684\u91cd\u8981\u6027<\/h4>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u590d\u7528\u6027\u8bf4\u8d77\u6765\u5bb9\u6613\u505a\u8d77\u6765\u96be\uff0c\u505a\u597d\u5b83\u4e0d\u4ec5\u9700\u8981\u826f\u597d\u7684\u8bbe\u8ba1\uff0c\u8fd8\u9700\u8981\u826f\u597d\u7684\u6587\u6863\u3002\u5373\u4f7f\u6211\u4eec\u770b\u5230\u597d\u7684\u8bbe\u8ba1\uff08\u8fd9\u79cd\u60c5\u51b5\u4ecd\u7136\u5f88\u5c11\u89c1\uff09\uff0c\u4f46\u5982\u679c\u6ca1\u6709\u597d\u7684\u6587\u6863\uff0c\u6211\u4eec\u4e5f\u4e0d\u4f1a\u770b\u5230\u7ec4\u4ef6\u7684\u91cd\u7528\u3002<\/p><cite>- D. L. Parnas\uff0c_\u8f6f\u4ef6\u8001\u5316\u3002 \u7b2c\u5341\u516d\u5c4a\u56fd\u9645\u8f6f\u4ef6\u5de5\u7a0b\u4f1a\u8bae\uff0c1994\u5e74<\/cite><\/blockquote>\n\n\n\n<h4 class=\"wp-block-heading\">2.7 \u5ba1\u614e\u8ba4\u771f\u7684\u8bb0\u5f55<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u8bb0\u5f55<strong>\u6bcf\u4e00\u4e2a<\/strong>\u7c7b\u3001\u63a5\u53e3\u3001\u65b9\u6cd5\u3001\u6784\u9020\u51fd\u6570\u3001\u53c2\u6570\u548c\u5f02\u5e38<ul><li>Class\uff1a\u5b9e\u4f8b\u4f5c\u7528\u662f\u4ec0\u4e48<\/li><li>\u65b9\u6cd5\uff1a\u65b9\u6cd5\u548c\u4f7f\u7528\u8005\u95f4\u7684\u5408\u7ea6<ul><li>\u5148\u51b3\u6761\u4ef6\u3001\u540e\u7f6e\u6761\u4ef6\u3001\u526f\u4f5c\u7528<\/li><\/ul><\/li><li>\u53c2\u6570\uff1a\u6807\u660e\u5355\u5143\uff08units\uff09\u3001\u7ec4\u6210\uff08form\uff09\u3001\u6240\u6709\u6743<\/li><\/ul><\/li><li>\u8ba4\u771f\u8bb0\u5f55\u4f5c\u7528\u57df\uff08Document state space very carefully\uff09<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2.8 \u8003\u8651API\u8bbe\u8ba1\u51b3\u7b56\u7684\u6027\u80fd\u540e\u679c<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u9519\u8bef\u7684\u51b3\u7b56\u4f1a\u9650\u5236\u6027\u80fd<ul><li>\u4f7f\u7c7b\u578b\u53ef\u53d8<\/li><li>\u63d0\u4f9b\u6784\u9020\u51fd\u6570\u800c\u4e0d\u662f\u9759\u6001\u5de5\u5382<\/li><li>\u4f7f\u7528\u5b9e\u73b0\u7c7b\u578b\u800c\u4e0d\u662f\u63a5\u53e3<\/li><\/ul><\/li><li>\u4e0d\u8981\u626d\u66f2 API \u4ee5\u83b7\u5f97\u6027\u80fd<ul><li>\u57fa\u672c\u7684\u6027\u80fd\u95ee\u9898\u5c06\u5f97\u5230\u89e3\u51b3\uff0c\u4f46\u5934\u75db\u5c06\u6c38\u8fdc\u4f34\u968f\u7740\u4f60<\/li><li>\u597d\u7684\u8bbe\u8ba1\u901a\u5e38\u4e0e\u597d\u7684\u6027\u80fd\u76f8\u4e00\u81f4<\/li><\/ul><\/li><li>API \u8bbe\u8ba1\u51b3\u7b56\u5bf9\u6027\u80fd\u7684\u5f71\u54cd\u662f\u771f\u5b9e\u548c\u6c38\u4e45\u7684<ul><li><strong>Component.getSize() <\/strong>\u8fd4\u56de <strong>Dimension<\/strong><\/li><li><strong>Dimension<\/strong> \u662f\u53ef\u53d8\u7684<\/li><\/ul><ul><li>\u6bcf\u4e00\u6b21 getSize \u8c03\u7528\u90fd\u9700\u8981\u5206\u914d <strong>Dimension<\/strong> \u5185\u5b58<\/li><li>\u5bfc\u81f4\u6210\u5343\u4e0a\u4e07\u7684\u4e0d\u5fc5\u8981\u7684\u5bf9\u8c61\u5185\u5b58\u5206\u914d<\/li><li>\u5728 1.2 \u4e2d\u589e\u52a0\u4e86\u66ff\u4ee3\u65b9\u6848\uff1b\u4e0d\u8fc7\u65e7\u7684\u4ee3\u7801\u4ecd\u7136\u5f88\u6162<\/li><\/ul><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2.9 API \u5fc5\u987b\u4e0e\u5e73\u53f0\u548c\u5e73\u5171\u5904<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u9075\u5b88\u60ef\u4f8b<ul><li>\u9075\u5b88\u6807\u51c6\u547d\u540d\u7ea6\u5b9a<\/li><li>\u907f\u514d\u5e9f\u5f03\uff08\u8fc7\u65f6\uff09\u7684\u53c2\u6570\u548c\u8fd4\u56de\u7c7b\u578b<\/li><li>\u6a21\u62df\u6838\u5fc3 API \u548c\u7f16\u7a0b\u8bed\u8a00\u7684\u6a21\u5f0f<\/li><\/ul><\/li><li>\u5229\u7528 API \u53cb\u597d\u7684\u7279\u6027<ul><li>\u6cdb\u578b\u3001\u53d8\u91cf\u53c2\u6570\u3001\u679a\u4e3e\u3001\u9ed8\u8ba4\u53c2\u6570<\/li><\/ul><\/li><li>\u4e86\u89e3\u5e76\u907f\u514d API \u7f3a\u9677\u4e0e\u9677\u9631<ul><li>Finalizers\u3001public static final arrays\uff08\uff1f\uff09<\/li><\/ul><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u4e09\u3001\u7c7b\u7684\u8bbe\u8ba1<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">3.1 \u6700\u5c0f\u5316\u6613\u53d8\u6027<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u9664\u975e\u6709\u5145\u5206\u7684\u7406\u7531\uff0c\u5426\u5219\u7c7b\u5e94\u8be5\u662f\u4e0d\u53ef\u53d8\u7684<ul><li>\u4f18\u70b9\uff1a\u7b80\u5355\uff0c\u7ebf\u7a0b\u5b89\u5168\uff0c\u53ef\u91cd\u7528<\/li><li>\u7f3a\u70b9\uff1a\u4e3a\u6bcf\u4e2a\u503c\u521b\u5efa\u5bf9\u8c61<\/li><\/ul><\/li><li>\u5982\u679c\u6613\u53d8\uff0c\u4fdd\u8bc1\u4f5c\u7528\u57df\u8db3\u591f\u5c0f\uff0c\u5b9a\u4e49\u660e\u786e<ul><li>\u660e\u786e\u4ec0\u4e48\u65f6\u673a\u8c03\u7528\u54ea\u4e2a\u65b9\u6cd5\u662f\u5408\u6cd5\u7684<\/li><\/ul><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u574f\u7684\u793a\u4f8b\uff1aDate\uff0cCalendar<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u597d\u7684\u793a\u4f8b\uff1aTimerTask<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3.2 \u4ec5\u5728\u6709\u610f\u4e49\u7684\u65f6\u5019\u4f7f\u7528\u5b50\u7c7b<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b50\u7c7b\u5316\u610f\u5473\u7740\u53ef\u66ff\u4ee3\u6027\uff08\u91cc\u6c0f\u66ff\u6362\uff0cLiskov\uff09<ul><li>\u4ec5\u5f53 is-a \u7684\u5173\u7cfb\u5b58\u5728\u65f6\u624d\u4f7f\u7528\u5b50\u7c7b<\/li><li>\u5426\u5219\uff0c\u4f7f\u7528\u7ec4\u5408<\/li><\/ul><\/li><li>\u4e3a\u4e86\u4fbf\u4e8e\u5b9e\u73b0\uff0c\u516c\u5171\u7c7b\u4e0d\u5e94\u8be5\u5b50\u7c7b\u5316\u5176\u4ed6\u516c\u5171\u7c7b<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u574f\u7684\u793a\u4f8b\uff1a<strong>Properties extends Hashtable\uff0c Stack extends Vector<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u597d\u7684\u793a\u4f8b\uff1a<strong>Set extends Collection<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Collection<\/strong>\u662f\u63a5\u53e3\uff0c<strong>Hashtable<\/strong> \u548c <strong>Vector<\/strong>\u662f\u5177\u4f53\u7684\u5b9e\u73b0\u3002<\/p><\/blockquote>\n\n\n\n<h4 class=\"wp-block-heading\">3.3 \u4e3a\u7ee7\u627f\u8bbe\u8ba1\u5e76\u6587\u6863\u8bb0\u5f55\u5b83\uff0c\u5426\u5219\u7981\u6b62\u4f7f\u7528\u7ee7\u627f<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u7ee7\u627f\u7834\u574f\u5c01\u88c5<ul><li>\u5b50\u7c7b\u5bf9\u7236\u7c7b\u7684\u5b9e\u73b0\u7ec6\u8282\u654f\u611f<\/li><\/ul><\/li><li>\u5982\u679c\u5141\u8bb8\u5b50\u7c7b\u5316\uff0c\u6587\u6863\u6807\u660e <em>\u4f5c\u7528<\/em><ul><li>\u65b9\u6cd5\u5982\u4f55\u4e92\u76f8\u8c03\u7528<\/li><\/ul><\/li><li>\u4fdd\u5b88\u653f\u7b56\uff1a\u6240\u6709\u5b9e\u4f53\u7c7b\u90fd\u662ffinal<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u574f\u7684\u793a\u4f8b\uff1aMany concrete classes in J2SE libraries<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u597d\u7684\u793a\u4f8b\uff1a<strong>AbstractSet<\/strong>, <strong>AbstractMap<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u56db\u3001\u65b9\u6cd5\u8bbe\u8ba1<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">4.1 \u4e0d\u8981\u8ba9\u5ba2\u6237\u7aef\u505a\u6a21\u5757\u80fd\u505a\u7684\u4efb\u4f55\u4e8b\u60c5<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u51cf\u5c11\u5bf9\u6837\u677f\u4ee3\u7801\u7684\u9700\u6c42<ul><li>\u901a\u5e38\u901a\u8fc7\u526a\u5207-\u7c98\u8d34\u5b8c\u6210<\/li><li>\u4e11\u964b\uff0c\u70e6\u4eba\uff0c\u5bb9\u6613\u51fa\u9519<\/li><\/ul><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"379\" src=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-1024x379.png\" alt=\"\" class=\"wp-image-1068\" srcset=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-1024x379.png 1024w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-300x111.png 300w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-768x285.png 768w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-1536x569.png 1536w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-2048x759.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">4.2 \u4e0d\u8981\u8fdd\u53cd\u6700\u5c0f\u60ca\u5947\u539f\u5219<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>API \u7684\u4f7f\u7528\u8005\u4e0d\u5e94\u4e3a API \u7684\u884c\u4e3a\u611f\u5230\u60ca\u8bb6<ul><li>\u503c\u5f97\u4ed8\u51fa\u7684\u989d\u5916\u52aa\u529b<\/li><li>\u751a\u81f3\u503c\u5f97\u964d\u4f4e\u6027\u80fd<\/li><\/ul><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"219\" src=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-1-1024x219.png\" alt=\"\" class=\"wp-image-1074\" srcset=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-1-1024x219.png 1024w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-1-300x64.png 300w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-1-768x164.png 768w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-1-1536x329.png 1536w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-1-2048x438.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">4.3 Fail Fast\u2013\u9519\u8bef\u53d1\u751f\u540e\u5c3d\u5feb\u62a5\u544a<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6700\u597d\u662f\u5728\u7f16\u8bd1\u65f6- \u9759\u6001\u7c7b\u578b\u3001\u6cdb\u578b<\/li><li>\u8fd0\u884c\u65f6\uff0c\u6700\u597d\u5728\u7b2c\u4e00\u4e2a\u9519\u8bef\u7684\u65b9\u6cd5\u8c03\u7528\u662f\u65f6<ul><li>\u65b9\u6cd5\u7684\u5931\u8d25\u5e94\u8be5\u662f\u539f\u5b50\u7684<\/li><\/ul><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"332\" src=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-2-1024x332.png\" alt=\"\" class=\"wp-image-1084\" srcset=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-2-1024x332.png 1024w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-2-300x97.png 300w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-2-768x249.png 768w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-2-1536x497.png 1536w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-2-2048x663.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">4.4 \u5bf9\u6240\u6709\u53ef\u7528\u6570\u636e\u63d0\u4f9b\u5b57\u7b26\u4e32\u5f62\u5f0f\u7684\u7f16\u7a0b\u8bbf\u95ee<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5426\u5219\uff0c\u5ba2\u6237\u7aef\u9700\u8981\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32<ul><li>\u8fd9\u5f88\u75db\u82e6<\/li><li>\u66f4\u574f\u7684\u662f\uff0c\u5c06\u5b57\u7b26\u4e32\u683c\u5f0f\u8f6c\u5316\u4e3a\u771f\u5b9e\u7684API<\/li><\/ul><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"433\" src=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-3-1024x433.png\" alt=\"\" class=\"wp-image-1090\" srcset=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-3-1024x433.png 1024w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-3-300x127.png 300w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-3-768x325.png 768w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-3-1536x649.png 1536w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-3-2048x866.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">4.5 \u91cd\u8f7d\u8981\u5c0f\u5fc3<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u907f\u514d\u4e0d\u660e\u786e\u7684\u91cd\u8f7d<ul><li>\u591a\u4e2a\u91cd\u8f7d\u65b9\u6cd5\u5b9e\u9645\u7ed3\u679c\u4e00\u81f4<\/li><\/ul><ul><li>\u4fdd\u5b88\uff1a\u6ca1\u6709\u4e24\u4e2a\u91cd\u8f7d\u65b9\u6cd5\u7684\u53c2\u6570\u6570\u91cf\u76f8\u540c<\/li><\/ul><\/li><li>\u4ec5\u4ec5\u56e0\u4e3a\u4f60\u53ef\u4ee5\uff0c\u5e76\u4e0d\u610f\u5473\u7740\u4f60\u5e94\u8be5<ul><li>\u901a\u5e38\u66f4\u597d\u7684\u529e\u6cd5\u662f\u4f7f\u7528\u4e0d\u540c\u7684\u540d\u5b57<\/li><\/ul><\/li><li>\u5982\u679c\u4f60\u4e00\u5b9a\u8981\u63d0\u4f9b\u4e0d\u660e\u786e\u7684\u91cd\u8f7d\u65b9\u6cd5\uff0c\u786e\u4fdd\u4ed6\u4eec\u5bf9\u540c\u6837\u7684\u53c2\u6570\u6709\u540c\u6837\u7684\u884c\u4e3a<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"112\" src=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-4-1024x112.png\" alt=\"\" class=\"wp-image-1096\" srcset=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-4-1024x112.png 1024w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-4-300x33.png 300w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-4-768x84.png 768w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-4-1536x167.png 1536w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-4-2048x223.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">4.6 \u4f7f\u7528\u6070\u5f53\u7684\u53c2\u6570\u548c\u8fd4\u56de\u6570\u636e\u7c7b\u578b<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4f18\u5148\u9009\u62e9\u63a5\u53e3\u800c\u4e0d\u662f\u7c7b\u4f5c\u4e3a\u8f93\u5165<ul><li>\u80fd\u4fdd\u8bc1\u7075\u6d3b\u6027\u548c\u6027\u80fd<\/li><\/ul><\/li><li>\u5728\u53ef\u80fd\u8f93\u5165\u53c2\u6570\u7c7b\u578b\u4e2d\uff0c\u4f7f\u7528\u6700\u5177\u4f53\u7684\u6570\u636e\u7c7b\u578b<ul><li>\u5c06\u9519\u8bef\u4ece\u8fd0\u884c\u65f6\u524d\u7f6e\u5230\u7f16\u8bd1\u65f6<\/li><\/ul><\/li><li>\u5982\u679c\u6709\u66f4\u597d\u7684\u9009\u62e9\u7c7b\u578b\uff0c\u5c31\u4e0d\u8981\u4f7f\u7528\u5b57\u7b26\u4e32<ul><li>\u5b57\u7b26\u4e32\u7e41\u7410\uff0c\u5bb9\u6613\u51fa\u9519\u4e14\u8fd0\u884c\u7f13\u6162<\/li><\/ul><\/li><li>\u4e0d\u8981\u5bf9\u8d27\u5e01\u6570\u503c\u4f7f\u7528\u6d6e\u70b9\u7c7b\u578b<ul><li>\u4e8c\u8fdb\u5236\u6d6e\u70b9\u4f1a\u5bfc\u81f4\u7ed3\u679c\u4e0d\u591f\u7cbe\u786e<\/li><\/ul><\/li><li>\u4f7f\u7528 double\uff0864 bits\uff09\u800c\u4e0d\u662ffloat\u7c7b\u578b\uff0832 bits\uff09<ul><li>\u7cbe\u5ea6\u635f\u5931\u4e3a\u5b9e\uff0c\u6027\u80fd\u635f\u5931\u53ef\u5ffd\u7565\u4e0d\u8ba1<\/li><\/ul><\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4.7 \u4f7f\u7528\u4e00\u81f4\u6027\u7684\u53c2\u6570\u987a\u5e8f<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5982\u679c\u53c2\u6570\u7c7b\u578b\u76f8\u540c\uff0c\u5219\u5c24\u4e3a\u91cd\u8981<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"401\" src=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-5-1024x401.png\" alt=\"\" class=\"wp-image-1112\" srcset=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-5-1024x401.png 1024w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-5-300x117.png 300w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-5-768x301.png 768w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-5-1536x602.png 1536w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-5-2048x802.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">4.8 \u907f\u514d\u957f\u53c2\u6570\u5217\u8868<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4e09\u4e2a\u6216\u66f4\u5c11\u7684\u53c2\u6570\u662f\u7406\u60f3\u7684<ul><li>\u66f4\u591a\u53c2\u6570\u7528\u6237\u5c06\u4e0d\u5f97\u4e0d\u53c2\u8003\u6587\u6863<\/li><\/ul><\/li><li>\u53c2\u6570\u7c7b\u578b\u76f8\u540c\u7684\u957f\u53c2\u6570\u5217\u8868\u6709\u5bb3<ul><li>\u7a0b\u5e8f\u5458\u5f88\u5bb9\u6613\u5c06\u53c2\u6570\u987a\u5e8f\u5199\u53cd\u800c\u72af\u9519<\/li><li>\u7a0b\u5e8f\u4ecd\u7136\u53ef\u4ee5\u7f16\u8bd1\uff0c\u8fd0\u884c\uff0c\u4f46\u662f\u884c\u4e3a\u5f02\u5e38<\/li><\/ul><\/li><li>\u4e24\u79cd\u7f29\u77ed\u53c2\u6570\u5217\u8868\u7684\u65b9\u6cd5\uff1a<ul><li>\u62c6\u5206\u65b9\u6cd5<\/li><li>\u521b\u5efa Helper \u7c7b\u4ee5\u4fdd\u5b58\u53c2\u6570<\/li><\/ul><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"158\" src=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-6-1024x158.png\" alt=\"\" class=\"wp-image-1122\" srcset=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-6-1024x158.png 1024w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-6-300x46.png 300w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-6-768x118.png 768w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-6-1536x236.png 1536w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-6-2048x315.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">4.9 \u907f\u514d\u5f02\u5e38\u8fd4\u56de\u503c\u5904\u7406<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u8fd4\u56de\u5143\u7d20\u6570\u4e3a 0 \u7684\u6570\u7ec4\u6216\u96c6\u5408\u7c7b\uff0c\u800c\u4e0d\u662f null<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"248\" src=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-7-1024x248.png\" alt=\"\" class=\"wp-image-1129\" srcset=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-7-1024x248.png 1024w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-7-300x73.png 300w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-7-768x186.png 768w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-7-1536x373.png 1536w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-7-2048x497.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e94\u3001\u5f02\u5e38\u8bbe\u8ba1<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">5.1 \u629b\u51fa\u5f02\u5e38\u6807\u660e\u5f02\u5e38\u72b6\u51b5<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4e0d\u8981\u5f3a\u5236\u5ba2\u6237\u7aef\u5bf9\u63a7\u5236\u6d41\u4f7f\u7528\u5f02\u5e38<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"597\" src=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-8-1024x597.png\" alt=\"\" class=\"wp-image-1133\" srcset=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-8-1024x597.png 1024w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-8-300x175.png 300w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-8-768x448.png 768w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-8-1536x896.png 1536w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-8.png 1650w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>\u76f8\u5e94\u7684\uff0c\u4e5f\u4e0d\u8981\u6084\u6084\u7684\u5931\u8d25<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"109\" src=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-9-1024x109.png\" alt=\"\" class=\"wp-image-1134\" srcset=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-9-1024x109.png 1024w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-9-300x32.png 300w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-9-768x82.png 768w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-9-1536x163.png 1536w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-9.png 1620w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">5.2 \u652f\u6301\u672a\u7ecf\u68c0\u67e5\u7684\u5f02\u5e38<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5df2\u68c0\u67e5 - \u5ba2\u6237\u7aef\u5fc5\u987b\u6267\u884c\u6062\u590d\u64cd\u4f5c<\/li><li>\u672a\u68c0\u67e5 - \u7a0b\u5e8f\u9519\u8bef<\/li><li>\u8fc7\u5ea6\u4f7f\u7528\u5f02\u5e38\u68c0\u67e5\u4ea7\u751f\u6837\u677f\u4ee3\u7801<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"338\" src=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-10-1024x338.png\" alt=\"\" class=\"wp-image-1135\" srcset=\"https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-10-1024x338.png 1024w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-10-300x99.png 300w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-10-768x254.png 768w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-10-1536x507.png 1536w, https:\/\/t.n-years.com\/wp-content\/uploads\/2020\/10\/image-10-2048x676.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">5.3 \u5728\u5f02\u5e38\u4e2d\u5305\u542b\u6545\u969c\u6355\u83b7\u4fe1\u606f<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5141\u8bb8\u8bca\u65ad\uff0c\u4fee\u590d\u6216\u6062\u590d<\/li><li>\u5bf9\u4e8e\u672a\u7ecf\u68c0\u67e5\u7684\u5f02\u5e38\uff0c\u6d88\u606f\u5c31\u8db3\u591f\u4e86<\/li><li>\u5bf9\u4e8e\u5df2\u68c0\u67e5\u7684\u5f02\u5e38\uff0c\u63d0\u4f9b\u8bbf\u95ee\u5668<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u516d\u3001\u91cd\u6784 API \u8bbe\u8ba1<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">6.1 Vector\u4e2d\u7684\u5b50\u5217\u8868\u64cd\u4f5c<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Vector {\n       public int indexOf(Object elem, int index); public int \n       lastIndexOf(Object elem, int index); ...\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4e0d\u591f\u5f3a\u5927 - \u4ec5\u652f\u6301\u641c\u7d22<\/li><li>\u6ca1\u6709\u6587\u6863\u5f88\u96be\u4f7f\u7528<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u5b50\u5217\u8868\u91cd\u6784\uff1a<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>public interface List {\n       List subList(int fromIndex, int toIndex); ...\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6781\u5176\u5f3a\u5927-\u652f\u6301\u6240\u6709\u64cd\u4f5c<\/li><li>\u4f7f\u7528\u63a5\u53e3\u53ef\u51cf\u8f7b\u6982\u5ff5\u4e0a\u7684\u8d1f\u62c5<ul><li>\u9ad8\u6027\u4ef7\u6bd4<\/li><\/ul><\/li><li>\u65e0\u9700\u6587\u6863\uff0c\u6613\u4e8e\u4f7f\u7528<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">6.2 \u7ebf\u7a0b\u5c40\u90e8\u53d8\u91cf\uff08Thread-Local Variables\uff09<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Broken - inappropriate use of String as capability. \n\/\/ Keys constitute a shared global namespace.\npublic class ThreadLocal {\n       private ThreadLocal() { } \/\/ Non-instantiable\n       \/\/ Sets current thread\u2019s value for named variable.\n       public static void set(String key, Object value);\n       \/\/ Returns current thread\u2019s value for named variable.\n       public static Object get(String key); \n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u7ebf\u7a0b\u5c40\u90e8\u53d8\u91cf\u91cd\u6784\uff081\uff09<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ThreadLocal {\nprivate ThreadLocal() { } \/\/ Noninstantiable\n\n    public static class Key { Key() { } }\n    \/\/ Generates a unique, unforgeable key\n    public static Key getKey() { return new Key(); }\n    public static void set(Key key, Object value);\n    public static Object get(Key key);\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u53ef\u4ee5\u5de5\u4f5c\uff0c\u4f46\u9700\u8981\u4f7f\u7528\u6837\u677f\u4ee3\u7801<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>static ThreadLocal.Key serialNumberKey = ThreadLocal.getKey(); ThreadLocal.set(serialNumberKey, nextSerialNumber()); System.out.println(ThreadLocal.get(serialNumberKey));<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u7ebf\u7a0b\u5c40\u90e8\u53d8\u91cf\u91cd\u6784\uff082\uff09<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ThreadLocal {\n       public ThreadLocal() { } public void set(Object value); public \n       Object get();\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6e05\u9664API\u548c\u5ba2\u6237\u7aef\u4ee3\u7801\u4e2d\u7684\u6df7\u4e71<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>static ThreadLocal serialNumber = new ThreadLocal(); serialNumber.set(nextSerialNumber()); System.out.println(serialNumber.get());<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e03\u3001\u603b\u7ed3<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>API\u8bbe\u8ba1\u662f\u4e00\u95e8\u9ad8\u5c1a\u800c\u6709\u4ef7\u503c\u7684\u6280\u80fd<ul><li>\u4fc3\u8fdb\u4e86\u5927\u91cf\u7a0b\u5e8f\u5458\u3001\u7ec8\u7aef\u7528\u6237\u3001\u516c\u53f8\u53d1\u5c55<\/li><\/ul><\/li><li>\u8fd9\u6b21\u6f14\u8bb2\u6db5\u76d6\u4e86\u4e00\u4e9b\u542f\u53d1\u5f0f\u6280\u672f<ul><li>\u4e0d\u8981\u8fc7\u5206\u62d8\u6ce5\u4e8e\u5b83\u4eec\uff0c\u4f46\u662f\u2026<\/li><li>\u6ca1\u6709\u5145\u5206\u7684\u7406\u7531\u4e5f\u4e0d\u8981\u8fdd\u80cc\u5b83\u4eec<\/li><\/ul><\/li><li>API \u8bbe\u8ba1\u5f88\u96be<ul><li>\u4e0d\u662f\u5b64\u7acb\u7684\u6d3b\u52a8<\/li><li>\u5b8c\u7f8e\u662f\u65e0\u6cd5\u5b9e\u73b0\u7684\uff0c\u4f46\u65e0\u8bba\u5982\u4f55\u8981\u52aa\u529b<\/li><\/ul><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u53c2\u8003\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Service_provider_interface\">Service provider interface<\/a><\/li><li><a href=\"https:\/\/en.wikipedia.org\/wiki\/David_Parnas\">D. L. Parnas<\/a>\uff08\u5927\u536b\u00b7\u5e15\u5c14\u7eb3\u65af\uff09<\/li><li><a href=\"https:\/\/www.jianshu.com\/p\/8a40b8bb8e5b\">\u7b80\u4e66-API\u8bbe\u8ba1\u7684\u4e00\u4e9b\u6838\u5fc3\u539f\u5219<\/a> \uff082020-12-21\u8865\u5145\uff09<\/li><li><a href=\"https:\/\/asciiwwdc.com\/2010\/sessions\/138\">WWDC 2010 - API Design for Cocoa and Cocoa Touch<\/a><\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u94fe\u63a5\uff1aHow to Design a Good API and Why it Matters \u4f5c\u8005\u7b80\u4ecb\uff1a \u7ea6&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=817\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[18],"class_list":["post-817","post","type-post","status-publish","format-standard","hentry","category-6","tag-api-design"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=817"}],"version-history":[{"count":349,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/817\/revisions"}],"predecessor-version":[{"id":3705,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/817\/revisions\/3705"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}