{"id":1486,"date":"2022-08-12T08:24:53","date_gmt":"2022-08-12T00:24:53","guid":{"rendered":"https:\/\/zhuxinyong.com\/?p=1486"},"modified":"2022-08-16T23:37:17","modified_gmt":"2022-08-16T15:37:17","slug":"she-ji-mo-shi-javascript-zhong-de-shi-pei-qi-mo-s","status":"publish","type":"post","link":"https:\/\/zhuxinyong.com\/?p=1486","title":{"rendered":"\u8bbe\u8ba1\u6a21\u5f0f &#8211; JavaScript \u4e2d\u7684\u9002\u914d\u5668\u6a21\u5f0f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/08\/\u7b80\u7ea6\u9632\u63a7\u8981\u6c42\u516c\u4f17\u53f7\u9996\u56fe__2022-08-1417_44_25.png\" alt=\"\u7b80\u7ea6\u9632\u63a7\u8981\u6c42\u516c\u4f17\u53f7\u9996\u56fe__2022-08-14+17_44_25\" \/><\/p>\n<p>\u539f\u6587\u5730\u5740\uff1a<a href=\"https:\/\/dev.to\/carlillo\/design-patterns---adapter-2pi3\" target=\"_blank\" rel=\"noopener\">https:\/\/dev.to\/carlillo\/design-patterns&#8212;adapter-2pi3<\/a><\/p>\n<p>\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5c06\u4ecb\u7ecd\u4ec0\u4e48\u662f <code>Adapter Pattern<\/code> \u4ee5\u53ca\u600e\u6837\u548c\u4ec0\u4e48\u65f6\u5019\u4f7f\u7528\u5e94\u8be5\u4f7f\u7528\u5b83\u3002<\/p>\n<h2><a id=\"%E9%80%82%E9%85%8D%E5%99%A8%E6%A8%A1%E5%BC%8F%EF%BC%9A%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u9002\u914d\u5668\u6a21\u5f0f\uff1a\u57fa\u7840\u6982\u5ff5<\/h2>\n<blockquote>\n<p>\u9002\u914d\u5668\u6a21\u5f0f\u4f7f\u5f97\u4e24\u4e2a\u4e92\u4e0d\u76f8\u878d\u7684\u63a5\u53e3\u53ef\u4ee5\u4e00\u8d77\u4f7f\u7528\uff0c\u8fd9\u662f\u73b0\u5b9e\u4e16\u754c\u5bf9\u9002\u914d\u5668\u7684\u5b9a\u4e49\u3002\u63a5\u53e3\u53ef\u80fd\u4e92\u4e0d\u76f8\u878d\uff0c\u4f46\u5185\u90e8\u529f\u80fd\u5e94\u8be5\u6ee1\u8db3\u9700\u6c42\u3002\u9002\u914d\u5668\u8bbe\u8ba1\u6a21\u5f0f\u901a\u8fc7\u5c06\u4e00\u4e2a\u7c7b\u7684\u63a5\u53e3\u8f6c\u6362\u4e3a\u7528\u6237\u6240\u671f\u671b\u7684\u63a5\u53e3\uff0c\u4f7f\u672c\u4e0d\u517c\u5bb9\u7684\u7c7b\u53ef\u4ee5\u4e00\u8d77\u5de5\u4f5c\u3002 &#8212; Wikipedia<\/p>\n<\/blockquote>\n<blockquote>\n<p>\u8f6c\u6362\u4e00\u4e2a\u7c7b\u7684\u63a5\u53e3\u4ee5\u8fbe\u5230\u7528\u6237\u671f\u5f85\u7684\u53e6\u4e00\u4e2a\u63a5\u53e3\u3002\u9002\u914d\u5668\u8ba9\u90a3\u4e9b\u63a5\u53e3\u4e0d\u517c\u5bb9\u7684\u7c7b\u53ef\u4ee5\u4e00\u8d77\u5de5\u4f5c\u3002 &#8211;Design Patterns: Elements of Reusable Object-Oriented Software<\/p>\n<\/blockquote>\n<p>\u8fd9\u79cd\u8bbe\u8ba1\u6a21\u5f0f\u7684\u4e3b\u8981\u7279\u5f81\u662f\u4f7f\u62e5\u6709\u4e0d\u540c\u63a5\u53e3\u7684\u7c7b\u53ef\u4ee5\u4e00\u8d77\u5de5\u4f5c\u3002<\/p>\n<p>\u8fd9\u79cd\u6a21\u5f0f\u6709\u4e24\u4e2a\u7248\u672c\uff1a<\/p>\n<ul>\n<li>\u8fd0\u884c\u65f6 <code>object adapter<\/code> \u901a\u8fc7\u4ee3\u7406\u5230 <code>adaptee<\/code> \u5bf9\u8c61\u4e0a\u6765\u5b9e\u73b0 <code>target<\/code> \u63a5\u53e3\u3002<\/li>\n<li>\u7f16\u8bd1\u65f6 <code>class adapter<\/code> \u901a\u8fc7\u4ece <code>adaptee<\/code> \u7c7b\u7ee7\u627f\u6765\u5b9e\u73b0 <code>target<\/code> \u63a5\u53e3\u3002<\/li>\n<\/ul>\n<p>\u7531\u4e8e\u5305\u62ecJava\u5728\u5185\u7684\u8bb8\u591a\u8bed\u8a00\u90fd\u4e0d\u652f\u6301\u591a\u91cd\u7ee7\u627f\uff0c\u800c\u4e14\u4e0e\u8bb8\u591a\u95ee\u9898\u6709\u5173\uff0c\u6211\u4eec\u6ca1\u6709\u663e\u793a\u4f7f\u7528\u7c7b\u9002\u914d\u5668\u6a21\u5f0f\u7684\u5b9e\u73b0\u3002<\/p>\n<p>\u5bf9\u8c61\u9002\u914d\u5668\uff08\u53c8\u53eb\u9002\u914d\u5668\uff09\u5305\u542b\u5b83\u6240\u5305\u88c5\u7684\u7c7b\u7684\u4e00\u4e2a\u5b9e\u4f8b\u3002\u8fd9\u79cd\u8bbe\u8ba1\u6a21\u5f0f\u7684 UML \u56fe\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/08\/16604864054539.jpg\" alt=\"\" \/><\/p>\n<p><code>Adaptor<\/code> \u7c7b\u5305\u542b <code>Adaptee<\/code> \u7c7b\uff0c\u610f\u5473\u7740 <code>Adaptee<\/code> \u7c7b\u5c06\u4f1a\u88ab <code>Adaptor<\/code> \u4f7f\u7528\u3002<\/p>\n<h2><a id=\"%E9%80%82%E9%85%8D%E5%99%A8%E6%A8%A1%E5%BC%8F%EF%BC%9A%E4%BB%80%E4%B9%88%E6%97%B6%E5%80%99%E4%BD%BF%E7%94%A8\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u9002\u914d\u5668\u6a21\u5f0f\uff1a\u4ec0\u4e48\u65f6\u5019\u4f7f\u7528<\/h2>\n<ul>\n<li>\u6709\u4e00\u4e2a\u7c7b\u7684\u63a5\u53e3\u5e76\u4e0d\u6ee1\u8db3\u4f60\u7684\u9700\u6c42\u3002<\/li>\n<li>\u6709\u51e0\u4e2a\u5b50\u7c7b\uff0c\u4f46\u901a\u8fc7\u5b50\u7c7b\u5316\u6765\u9002\u914d\u5b83\u4eec\u7684\u63a5\u53e3\u662f\u4e0d\u5b9e\u9645\u7684\u3002<\/li>\n<\/ul>\n<h2><a id=\"%E9%80%82%E9%85%8D%E5%99%A8%E6%A8%A1%E5%BC%8F%EF%BC%9A%E4%BC%98%E5%8A%BF\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u9002\u914d\u5668\u6a21\u5f0f\uff1a\u4f18\u52bf<\/h2>\n<p>\u9002\u914d\u5668\u6a21\u5f0f\u6709\u4e00\u4e9b\u4f18\u52bf\uff0c\u603b\u7ed3\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<ul>\n<li>\u4ee3\u7801\u66f4\u5177\u6709\u590d\u7528\u6027\u548c\u5f39\u6027\u3002<\/li>\n<li>\u7b80\u6d01\u7684\u4ee3\u7801\u56e0\u4e3a\u7528\u6237\u7aef\/\u4e0a\u4e0b\u6587\u5728\u6bcf\u4e2a\u5177\u4f53\u7c7b\u4e2d\u6ca1\u6709\u4f7f\u7528\u4e0d\u540c\u7684\u63a5\u53e3\u800c\u662f\u5229\u7528\u591a\u6001\u6027\u6765\u4ea4\u6362\u4e0d\u540c\u7684\u9002\u914d\u5668\u3002<\/li>\n<\/ul>\n<h2><a id=\"%E9%80%82%E9%85%8D%E5%99%A8%E6%A8%A1%E5%BC%8F%E4%BE%8B%E5%AD%901%EF%BC%9A%E7%94%A8-javascript-typescript%E5%AE%9E%E7%8E%B0%E7%9A%84%E4%B8%80%E4%B8%AA%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%9D%A5%E5%88%B0%E5%9F%8E%E5%B8%82%E7%9A%84%E4%BE%8B%E5%AD%90\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u9002\u914d\u5668\u6a21\u5f0f &#8211; \u4f8b\u5b501\uff1a\u7528 JavaScript \/ TypeScript \u5b9e\u73b0\u7684\u4e00\u4e2a\u673a\u5668\u4eba\u6765\u5230\u57ce\u5e02\u7684\u4f8b\u5b50<\/h2>\n<p>\u6211\u5c06\u4f1a\u7528 JavaScript \/ TypeScript \u7ed9\u4f60\u6f14\u793a\u5982\u4f55\u5b9e\u73b0\u6b64\u8bbe\u8ba1\u6a21\u5f0f\u3002\u8bf7\u8bb0\u4f4f JavaScript \u7f3a\u5c11\u63a5\u53e3\u548c\u62bd\u8c61\u7c7b\u3002\u56e0\u6b64\uff0c\u7406\u89e3\u6b64\u6a21\u5f0f\u6700\u597d\u7684\u65b9\u5f0f\u662f\u901a\u8fc7\u4f8b\u5b50\u548c TypeScript\u3002\u5728\u6211\u4eec\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u8bbe\u60f3\u4e86\u4e00\u4e2a\u540d\u4e3a <code>Warrior<\/code> \u7684\u62bd\u8c61\u7c7b\u6765\u5b9a\u4e49 Warrior \u7684\u95ee\u9898\u3002\u4e00\u4e2a warrior \u6709\u8bb8\u591a\u4f46\u548c\u95ee\u9898\u5e76\u4e0d\u76f8\u5173\u7684\u5c5e\u6027\u4ee5\u53ca\u4e00\u4e2a\u540d\u4e3a <code>attack<\/code> \u7684\u65b9\u6cd5\u3002warriors \u6709\u7c7b\u578b\u5206\u7c7b\uff0c\u6bd4\u5982 <code>Saiyan<\/code> \u548c <code>Namekian<\/code> \u5b9a\u4e49\u4e86 <code>attack<\/code> \u65b9\u6cd5\u7684\u5177\u4f53\u5b9e\u73b0\uff0c\u4f46\u662f\u6709\u4e00\u4e2a\u65b0\u7c7b <code>Android<\/code> \u8fdb\u5165\u4e86\u8fd9\u4e2a\u7cfb\u7edf\u3002\u5b83\u5bf9 Warrior \u7684\u63a5\u53e3\u5e76\u4e0d\u6ee1\u610f\uff0c\u4ee5\u81f3\u4e8e\u5728\u5185\u90e8\u7528\u4e0d\u540c\u7684\u65b9\u6cd5\u5b9e\u73b0\u3002\u4e0b\u9762\u7684 UML \u56fe\u5c55\u793a\u4e86\u6211\u521a\u63cf\u8ff0\u7684\u573a\u666f\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/08\/16606256891831.jpg\" alt=\"\" \/><\/p>\n<p>\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528\u4e00\u4e2a\u9002\u914d\u5668\u6a21\u5f0f\uff0c\u5b83\u5305\u542b\u4e00\u4e2a\u6709 <code>Android<\/code> \u5bf9\u8c61\u7684\u7c7b\uff08<code>AndroidAdapter<\/code>\uff09\uff0c\u5e76\u4f7f\u7528\u5b83\u6765\u505a\u4e0e warriors \u7684\u63a5\u53e3\u517c\u5bb9\u3002\u4f7f\u7528\u9002\u914d\u5668\u6a21\u5f0f\u7684 UML \u56fe\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/08\/16606261287892.jpg\" alt=\"\" \/><\/p>\n<p>\u4e0e\u6a21\u578b\u548c\u63a5\u53e3\u76f8\u5173\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-plain_text\">export interface Warrior {\n  ATTACK_BASE: number;\n  attack(): number;\n}\n<\/code><\/pre>\n<pre><code class=\"language-plain_text\">import { Warrior } from '..\/interfaces\/warrior.interface';\n\nexport class Saiyan implements Warrior {\n  public ATTACK_BASE = 100;\n  public attack(): number {\n    return Math.random() * 100 + this.ATTACK_BASE;\n  }\n}\n<\/code><\/pre>\n<pre><code class=\"language-plain_text\">import { Warrior } from '..\/interfaces\/warrior.interface';\n\nexport class Namekian implements Warrior {\n  public ATTACK_BASE = 50;\n  public attack(): number {\n    return Math.random() * 50 + this.ATTACK_BASE;\n  }\n}\n<\/code><\/pre>\n<pre><code class=\"language-plain_text\">export class Android {\n  public punch(): number {\n    return 10;\n  }\n  public kick(): number {\n    return Math.random() * this.punch() + this.punch();\n  }\n}\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/08\/16606623343111.jpg\" alt=\"\" \/><\/p>\n<p>\u5c31\u50cf\u4f60\u770b\u5230\u7684 <code>Android<\/code> \u7c7b\u5e76\u6ca1\u6709\u5b9e\u73b0 warrior \u7684\u63a5\u53e3\u3002\u6240\u4ee5\uff0c<code>AndroidAdapter<\/code> \u7c7b\u5c31\u662f\u7528\u6765\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u3002<\/p>\n<pre><code class=\"language-plain_text\">import { Warrior } from '..\/interfaces\/warrior.interface';\nimport { Android } from '.\/android.model';\n\nexport class AndroidAdapter implements Warrior {\n  constructor(private android: Android) {}\n  public ATTACK_BASE = 50;\n  public attack(): number {\n    return this.android.kick() + this.android.punch() + this.ATTACK_BASE;\n  }\n}\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/08\/16606626574592.jpg\" alt=\"\" \/><\/p>\n<p>\u6700\u540e\uff0c\u7528\u6237\u7aef\/\u4e0a\u4e0b\u6587\u82e5\u60f3\u4f7f\u7528\u8fd9\u4e09\u4e2a\u7c7b\uff0c\u5c31\u50cf\u4e0b\u9762\u7684\u4ee3\u7801\u4e00\u6837\uff0c\u9700\u8981 <code>AndroidAdapter<\/code> \u548c <code>Saiyan<\/code> \u3001<code>Namekian<\/code> \u4e00\u8d77\u4f7f\u7528\u3002<\/p>\n<pre><code class=\"language-plain_text\">import { Saiyan } from '.\/models\/saiyan.model';\nimport { Namekian } from '.\/models\/namekian';\nimport { AndroidAdapter } from '.\/models\/android-adapter.model';\nimport { Android } from '.\/models\/android.model';\n\nconst goku = new Saiyan();\nconst vegeta = new Saiyan();\nconst piccolo = new Namekian();\nconst C17 = new AndroidAdapter(new Android());\n\nconsole.log(`Goku attack: ${goku.attack()}`);\nconsole.log(`Vegeta attack: ${vegeta.attack()}`);\nconsole.log(`Piccolo attack: ${piccolo.attack()}`);\nconsole.log(`C17 attack: ${C17.attack()}`);\n<\/code><\/pre>\n<h2><a id=\"%E9%80%82%E9%85%8D%E5%99%A8%E6%A8%A1%E5%BC%8F%E4%BE%8B%E5%AD%902%EF%BC%9A%E7%94%A8-javascript-typescript%E6%9D%A5%E5%AE%9E%E7%8E%B0%E5%A4%9A%E4%B8%AA%E7%A7%8D%E6%97%8F%E4%B8%80%E8%B5%B7%E5%B7%A5%E4%BD%9C\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u9002\u914d\u5668\u6a21\u5f0f &#8211; \u4f8b\u5b502\uff1a\u7528 JavaScript \/ TypeScript \u6765\u5b9e\u73b0\u591a\u4e2a\u79cd\u65cf\u4e00\u8d77\u5de5\u4f5c<\/h2>\n<p>\u9002\u914d\u5668\u6a21\u5f0f\u53ef\u4ee5\u89e3\u51b3\u7684\u53e6\u4e00\u4e2a\u6709\u8da3\u95ee\u9898\u662f\uff0c\u5f53\u6709\u591a\u4e2a\u4e0d\u540c\u63a5\u53e3\u7684\u7c7b\u4f46\u5b83\u4eec\u9700\u8981\u4e00\u8d77\u5de5\u4f5c\u3002\u5728\u4e0b\u9762\u7684 UML \u56fe\u4f60\u53ef\u4ee5\u770b\u5230\u6b64\u60c5\u666f\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/08\/16606631550760.jpg\" alt=\"\" \/><\/p>\n<p>\u6bcf\u4e2a\u7c7b\u6709\u4e00\u4e2a\u65b0\u7684\u9002\u914d\u5668\u7c7b\uff0c\u9002\u914d\u5668\u7c7b\u5305\u542b\u6700\u521d\u7684\u5bf9\u8c61\u548c\u4ece\u63a5\u53e3\u5b9e\u73b0\u7684\u65b9\u6cd5\uff0c\u8fd9\u4e2a\u4f8b\u5b50\u7684\u4ee3\u7801\u5f88\u7b80\u5355\uff1a<\/p>\n<pre><code class=\"language-plain_text\">export class Human {\n  public sharedPower(): number {\n    return 10;\n  }\n}\nexport class Namekian {\n  public getPower(): number {\n    return Math.random() * 20 + 20;\n  }\n}\nexport class Saiyan {\n  myPowerPart1(): number {\n    return Math.random() * 100 + 100;\n  }\n  myPowerPart2(): number {\n    return Math.random() * 1000 + 500;\n  }\n}\n<\/code><\/pre>\n<p>\u4ee5\u53ca\u5b83\u4eec\u5404\u81ea\u7684\u9002\u914d\u5668\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-plain_text\">import { PureRace } from '..\/interfaces\/pure-race.interface';\nimport { Human } from '.\/human.model';\n\nexport class HumanAdapter implements PureRace {\n  constructor(private human: Human) {}\n\n  public genki(): number {\n    return this.human.sharedPower();\n  }\n}\n\n\/**\/\n\nimport { PureRace } from '..\/interfaces\/pure-race.interface';\nimport { Namekian } from '.\/namekian';\n\nexport class NamekianAdapter implements PureRace {\n  constructor(private namekian: Namekian) {}\n  public genki(): number {\n    return this.namekian.getPower();\n  }\n}\n\n\/**\/\n\nimport { PureRace } from '..\/interfaces\/pure-race.interface';\nimport { Saiyan } from '.\/saiyan.model';\n\nexport class SaiyanAdapter implements PureRace {\n  constructor(private saiyan: Saiyan) {}\n  public genki(): number {\n    return this.saiyan.myPowerPart1() + this.saiyan.myPowerPart2();\n  }\n}\n<\/code><\/pre>\n<p>\u6700\u540e\uff0c\u6240\u6709\u7684\u5bf9\u8c61\u90fd\u5728\u4e3a\u6253\u51fb\u90aa\u6076\u548c\u5b9e\u73b0\u4f1f\u5927\u7684\u529b\u91cf\u8d21\u732e\u80fd\u91cf\u3002<\/p>\n<pre><code class=\"language-plain_text\">import { Saiyan } from '.\/models\/saiyan.model';\nimport { Namekian } from '.\/models\/namekian';\nimport { Human } from '.\/models\/human.model';\nimport { SaiyanAdapter } from '.\/models\/saiyan-adapter.model';\nimport { NamekianAdapter } from '.\/models\/namekian-adapter.model';\nimport { HumanAdapter } from '.\/models\/human-adapter.model';\nimport { PureRace } from '.\/interfaces\/pure-race.interface';\n\nconst gohan = new SaiyanAdapter(new Saiyan());\nconst vegeta = new SaiyanAdapter(new Saiyan());\nconst piccolo = new NamekianAdapter(new Namekian());\nconst krilin = new HumanAdapter(new Human());\n\nconst everybody = [gohan, vegeta, piccolo, krilin];\n\nconst genki = everybody.reduce(\n  (power: number, pureRace: PureRace) =&gt; power + pureRace.genki(),\n  0\n);\nconsole.log(`everybody attack: ${genki}`);\n<\/code><\/pre>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/08\/16606636968598.jpg\" alt=\"\" \/><\/p>\n<h2><a id=\"%E6%80%BB%E7%BB%93\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u603b\u7ed3<\/h2>\n<p>\u5f53\u6709\u4e9b\u7c7b\u53ef\u4ee5\u4e00\u8d77\u5de5\u4f5c\u4f46\u5b83\u4eec\u7684\u63a5\u53e3\u4e0d\u517c\u5bb9\u65f6\uff0c\u9002\u914d\u5668\u6a21\u5f0f\u4f1a\u5728\u4f60\u7684\u9879\u76ee\u4e2d\u907f\u514d\u91cd\u590d\u4ee3\u7801\u3002\u8fd9\u7bc7\u6587\u7ae0\u4e2d\u4f60\u770b\u5230\u4f7f\u7528 JavaScript \/ TypeScript \u5b9e\u73b0\u7684\u4e00\u4e2a\u7b80\u5355\u4f8b\u5b50\u3002<\/p>\n<p>\u6700\u91cd\u8981\u7684\u4e0d\u662f\u50cf\u6211\u5c55\u793a\u7684\u90a3\u6837\u5b9e\u73b0\u6a21\u5f0f\uff0c\u800c\u662f\u8981\u80fd\u591f\u8ba4\u8bc6\u5230\u8fd9\u4e2a\u7279\u5b9a\u6a21\u5f0f\u80fd\u591f\u89e3\u51b3\u7684\u95ee\u9898\uff0c\u4ee5\u53ca\u4f60\u4f55\u65f6\u53ef\u4ee5\u6216\u4e0d\u53ef\u4ee5\u4f7f\u7528\u6b64\u6a21\u5f0f\u3002\u8fd9\u4e00\u70b9\u5f88\u5173\u952e\uff0c\u56e0\u4e3a\u5b9e\u73b0\u65b9\u5f0f\u4f1a\u56e0\u4f60\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\u4e0d\u540c\u800c\u4e0d\u540c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u5730\u5740\uff1ahttps:\/\/dev.to\/carlillo\/design-patterns&#038;#8212&#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":[2,20,3],"tags":[205,207],"class_list":["post-1486","post","type-post","status-publish","format-standard","hentry","category-all","category-frontend","category-tech","tag-design-patterns","tag-207"],"_links":{"self":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1486"}],"version-history":[{"count":1,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1486\/revisions"}],"predecessor-version":[{"id":1487,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1486\/revisions\/1487"}],"wp:attachment":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}