1"use strict";(self.webpackChunkjanzhou_123_github_io=self.webpackChunkjanzhou_123_github_io||[]).push([[5009],{3905:(t,e,r)=>{r.d(e,{Zo:()=>p,kt:()=>y});var n=r(7294);function a(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function o(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function i(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?o(Object(r),!0).forEach((function(e){a(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function c(t,e){if(null==t)return{};var r,n,a=function(t,e){if(null==t)return{};var r,n,a={},o=Object.keys(t);for(n=0;n<o.length;n++)r=o[n],e.indexOf(r)>=0||(a[r]=t[r]);return a}(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(n=0;n<o.length;n++)r=o[n],e.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(t,r)&&(a[r]=t[r])}return a}var s=n.createContext({}),l=function(t){var e=n.useContext(s),r=e;return t&&(r="function"==typeof t?t(e):i(i({},e),t)),r},p=function(t){var e=l(t.components);return n.createElement(s.Provider,{value:e},t.children)},u="mdxType",d={inlineCode:"code",wrapper:function(t){var e=t.children;return n.createElement(n.Fragment,{},e)}},m=n.forwardRef((function(t,e){var r=t.components,a=t.mdxType,o=t.originalType,s=t.parentName,p=c(t,["components","mdxType","originalType","parentName"]),u=l(r),m=a,y=u["".concat(s,".").concat(m)]||u[m]||d[m]||o;return r?n.createElement(y,i(i({ref:e},p),{},{components:r})):n.createElement(y,i({ref:e},p))}));function y(t,e){var r=arguments,a=e&&e.mdxType;if("string"==typeof t||a){var o=r.length,i=new Array(o);i[0]=m;var c={};for(var s in e)hasOwnProperty.call(e,s)&&(c[s]=e[s]);c.originalType=t,c[u]="string"==typeof t?t:a,i[1]=c;for(var l=2;l<o;l++)i[l]=r[l];return n.createElement.apply(null,i)}return n.createElement.apply(null,r)}m.displayName="MDXCreateElement"},8349:(t,e,r)=>{r.r(e),r.d(e,{assets:()=>s,contentTitle:()=>i,default:()=>d,frontMatter:()=>o,metadata:()=>c,toc:()=>l});var n=r(7462),a=(r(7294),r(3905));const o={title:"\u62bd\u8c61\u5de5\u5382\u6a21\u5f0f (Abstract Factory)",slug:"abstract-factory",sidebar_position:3},i=void 0,c={unversionedId:"pattern/abstract-factory",id:"pattern/abstract-factory",title:"\u62bd\u8c61\u5de5\u5382\u6a21\u5f0f (Abstract Factory)",description:"\u6982\u5ff5",source:"@site/docs/pattern/abstract-factory.md",sourceDirName:"pattern",slug:"/pattern/abstract-factory",permalink:"/docs/pattern/abstract-factory",draft:!1,editUrl:"https://github.com/facebook/docusaurus/tree/main/packages/create-docusaurus/templates/shared/docs/pattern/abstract-factory.md",tags:[],version:"current",sidebarPosition:3,frontMatter:{title:"\u62bd\u8c61\u5de5\u5382\u6a21\u5f0f (Abstract Factory)",slug:"abstract-factory",sidebar_position:3},sidebar:"tutorialSidebar",previous:{title:"\u5de5\u5382\u65b9\u6cd5\u6a21\u5f0f (Factory Method)",permalink:"/docs/pattern/factory-method"},next:{title:"\u751f\u6210\u5668\u6a21\u5f0f (Builder)",permalink:"/docs/pattern/builder"}},s={},l=[{value:"\u6982\u5ff5",id:"\u6982\u5ff5",level:2},{value:"\u793a\u4f8b",id:"\u793a\u4f8b",level:2}],p={toc:l},u="wrapper";function d(t){let{components:e,...r}=t;return(0,a.kt)(u,(0,n.Z)({},p,r,{components:e,mdxType:"MDXLayout"}),(0,a.kt)("h2",{id:"\u6982\u5ff5"},"\u6982\u5ff5"),(0,a.kt)("p",null,"\u62bd\u8c61\u5de5\u5382\u6a21\u5f0f\u662f\u4e00\u79cd\u521b\u5efa\u578b\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u5b83\u80fd\u521b\u5efa\u4e00\u7cfb\u5217\u76f8\u5173\u7684\u5bf9\u8c61\uff0c\u800c\u65e0\u9700\u6307\u5b9a\u5176\u5177\u4f53\u7c7b\u3002"),(0,a.kt)("p",null,"\u4f18\u70b9\uff1a"),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},"\u4f60\u53ef\u4ee5\u786e\u4fdd\u540c\u4e00\u5de5\u5382\u751f\u6210\u7684\u4ea7\u54c1\u76f8\u4e92\u5339\u914d\u3002"),(0,a.kt)("li",{parentName:"ol"},"\u4f60\u53ef\u4ee5\u907f\u514d\u5ba2\u6237\u7aef\u548c\u5177\u4f53\u4ea7\u54c1\u4ee3\u7801\u7684\u8026\u5408\u3002"),(0,a.kt)("li",{parentName:"ol"},"\u5355\u4e00\u804c\u8d23\u539f\u5219\u3002 \u4f60\u53ef\u4ee5\u5c06\u4ea7\u54c1\u751f\u6210\u4ee3\u7801\u62bd\u53d6\u5230\u540c\u4e00\u4f4d\u7f6e\uff0c \u4f7f\u5f97\u4ee3\u7801\u6613\u4e8e\u7ef4\u62a4\u3002"),(0,a.kt)("li",{parentName:"ol"},"\u5f00\u95ed\u539f\u5219\u3002 \u5411\u5e94\u7528\u7a0b\u5e8f\u4e2d\u5f15\u5165\u65b0\u4ea7\u54c1\u53d8\u4f53\u65f6\uff0c \u4f60\u65e0\u9700\u4fee\u6539\u5ba2\u6237\u7aef\u4ee3\u7801\u3002")),(0,a.kt)("p",null,"\u7f3a\u70b9\uff1a"),(0,a.kt)("ol",null,(0,a.kt)("li",{parentName:"ol"},"\u7531\u4e8e\u91c7\u7528\u8be5\u6a21\u5f0f\u9700\u8981\u5411\u5e94\u7528\u4e2d\u5f15\u5165\u4f17\u591a\u63a5\u53e3\u548c\u7c7b\uff0c \u4ee3\u7801\u53ef\u80fd\u4f1a\u6bd4\u4e4b\u524d\u66f4\u52a0\u590d\u6742\u3002")),(0,a.kt)("h2",{id:"\u793a\u4f8b"},"\u793a\u4f8b"),(0,a.kt)("p",null,"\u62bd\u8c61\u5de5\u5382\u6a21\u5f0f\u7684\u7279\u70b9\u662f\uff0c\u5b9a\u4e49\u4e00\u4e2a\u62bd\u8c61\u5de5\u5382\u7c7b\u6216\u8005\u63a5\u53e3\uff0c\u7531\u6b64\u5b9a\u4e49\u4e86\u89c4\u8303\u7684\u5de5\u5382\u65b9\u6cd5\uff08\u9020\u684c\u5b50\u3001\u9020\u6905\u5b50\uff09\uff0c\u5c06\u6b64\u89c4\u8303\u5e94\u7528\u4e8e\u5177\u4f53\u7684\u5de5\u5382\u7c7b\uff0c\u4f8b\u5982\u73b0\u4ee3\u98ce\u683c\u5de5\u5382\u548c\u590d\u53e4\u98ce\u683c\u5de5\u5382\uff0c\u751f\u4ea7\u51fa\u4e0d\u540c\u98ce\u683c\u7684\u684c\u5b50\u6905\u5b50\uff0c\u4ed6\u4eec\u5177\u6709\u76f8\u540c\u7684\u89c4\u8303\uff0c\u80fd\u5750\u3001\u80fd\u653e\u4e1c\u897f\u3002\u60f3\u521b\u5efa\u65b0\u7684\u98ce\u683c\u5bb6\u5177\uff0c\u53ea\u9700\u8981\u7f16\u5199\u65b0\u98ce\u683c\u7684\u5de5\u5382\u7c7b\u5e76\u5b9e\u73b0\u62bd\u8c61\u5de5\u5382\u63a5\u53e3\uff0c\u4e0d\u7528\u6539\u52a8\u4efb\u4f55\u5df2\u6709\u4ee3\u7801\u3002"),(0,a.kt)("p",null,"\u62bd\u8c61\u5de5\u5382\uff0c\u6784\u9020\u65b9\u6cd5\u8fd4\u56de\u7684\u662f\u62bd\u8c61\u7684\u4ea7\u54c1\u3002\u5ba2\u6237\u7aef\u4ee3\u7801\uff0c\u4e5f\u662f\u4e0e\u62bd\u8c61\u7684\u4ea7\u54c1\u8fdb\u884c\u4ea4\u4e92\uff0c\u65e0\u9700\u77e5\u9053\u5176\u5185\u90e8\u7ec6\u8282\uff0c\u53ea\u9700\u8981\u77e5\u9053\u6905\u5b50\u53ef\u4ee5 ",(0,a.kt)("inlineCode",{parentName:"p"},"sitOn"),"\uff0c\u684c\u5b50\u53ef\u4ee5 ",(0,a.kt)("inlineCode",{parentName:"p"},"putSomething")," \u3002"),(0,a.kt)("pre",null,(0,a.kt)("code",{parentName:"pre",className:"language-ts"},"interface AbstractFactory {\n createChair(): AbstractChair;\n createDesk(): AbstractDesk;\n}\n\ninterface AbstractChair {\n type: string;\n sitOn(): void;\n}\n\ninterface AbstractDesk {\n type: string;\n putSomething(): void;\n mixedFurniture(chair: AbstractChair): void;\n}\n\nclass MordernChair implements AbstractChair {\n type = 'MordernChair';\n sitOn() {\n console.log('Sitting on Mordern chair.');\n }\n}\n\nclass ClassicChair implements AbstractChair {\n type = 'ClassicChair';\n sitOn() {\n console.log('Sitting on Classic chair.');\n }\n}\n\nclass MordernDesk implements AbstractDesk {\n type = 'MordernDesk';\n putSomething() {\n console.log('Put something on Mordern desk.');\n }\n mixedFurniture(chair: AbstractChair): void {\n console.log(`Combo taste: ${chair.type} ${this.type}`);\n }\n}\nclass ClassicDesk implements AbstractDesk {\n type = 'ClassicDesk';\n putSomething() {\n console.log('Put something on Classic desk.');\n }\n mixedFurniture(chair: AbstractChair): void {\n console.log(`Combo taste: ${chair.type} ${this.type}`);\n }\n}\n\nclass MordernStyleFactory implements AbstractFactory {\n createChair(): AbstractChair {\n return new MordernChair();\n }\n createDesk(): AbstractDesk {\n return new MordernDesk();\n }\n}\n\nclass ClassicStyleFactory implements AbstractFactory {\n createChair(): AbstractChair {\n return new ClassicChair();\n }\n createDesk(): AbstractDesk {\n return new ClassicDesk();\n }\n}\n\n// \u5ba2\u6237\u7aef\u4ee3\u7801\u901a\u8fc7\u62bd\u8c61\u7c7b\u578b\u4e0e\u5de5\u5382\u548c\u4ea7\u54c1\u8fdb\u884c\u4ea4\u4e92\uff0c\u8fd9\u4f7f\u5f97\u8026\u5408\u5ea6\u5f88\u4f4e\nfunction ClientCode(factory: AbstractFactory) {\n // \u6839\u636e\u4f20\u5165\u7684\u5de5\u5382\uff0c\u521b\u5efa\u5bf9\u5e94\u98ce\u683c\u7684\u5bb6\u5177\n const chair = factory.createChair();\n const desk = factory.createDesk();\n chair.sitOn();\n // \u684c\u6905\u6df7\u5408\u5957\u9910\n desk.mixedFurniture(chair);\n}\n\n// \u73b0\u4ee3\u98ce\u683c\u5de5\u5382\nClientCode(new MordernStyleFactory());\n")))}d.isMDXComponent=!0}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.