23个设计模式C#代码.docx
《23个设计模式C#代码.docx》由会员分享,可在线阅读,更多相关《23个设计模式C#代码.docx(14页珍藏版)》请在第壹文秘上搜索。
1、/AbstractFactory/Intent:Provideaninterfaceforcreatingfamiliesofrelatedor/dependentobjectswithoutspecifyingtheirconcreteclasses”./Forfurtherinformation,readDesignPatterns,p87,Gammaetal.,/Addison-Wesley,ISBN:0-201-63361-2*Notes:* Whentheconstructionneededinvolvesmanyobjects,possibleorganised* inmulti-
2、facetedarrangements,theentireconstructioncanbedelegated* toanabstractfactory.Thisexposesstandardisedcreationfunctionality* whichcanbecustomisedinconcreteimplementationtosuityourspecific* needs,andavoidembeddingthisinformationinhigherlevelcode-it* justneedstoknowhowtocalltheabstractfactory.* Inthissa
3、mple,wehaveaframeworkwiththreeabstractoperatingclasses,* calledDPDocument,DPWorkspaceandDPViewandoneabstractconstruction* class,calledDPFactory.napplication-levelclass,calledDPApplication* isresponsibleforconstruction.* Wehaveaseriesofapp1ication-1eve1operatingclassesderivedfromthis* framework-MyDoc
4、ument,MyWorkspaceandMyView.Fordesignreasonswe* assumewewishtoinstantiatethesefrominsideDPApplication.Asthere* aremultipleobjectsneededandtheycouldbearrangedindifferent* lattices,weuseafactory,MyFactory(inourexample,thereareall* simplesiblings),whichiscalledinsideDPApplication.*/namespaceAbstractFact
5、oryDesignPatternusingSystem;/Theseclassescouldbepartofaframework,/whichwewillcallDP/=abstractclassDPDocumentabstractpublicvoidDump();abstractclassDPWorkspaceabstractpublicvoidDump();DPViewpublicvoidDump();abstractclass(abstractabstractclassabstractabstractabstractDPFactorypublicDPDocumentCreateDocum
6、ent();publicDPViewCreateViewO;publicDPWorkspaceCreateWorkspaceO;abstractclassDPApplication(protectedDPDocumentdoc;protectedDPWorkspaceworkspace;protectedDPViewview;publicvoidConstructObjects(DPFactoryfactory)(/Createobjectsasneededdoc=factory.CreateDocumentO;workspace=factory,CreateWorkspaceO;view=f
7、actory.CreateViewO;publicvoidDumpState()(if(doc!-null)doc.Dump();if(workspace!=null)workspace.Dump();if(view!=null)view.DumpO;)/TheseclassescouldbepartofanapplicationclassMyApplication:DPApplicationMyFactorymyFactory=newMyFaCtory();overridepublicvoidDump()(Console.Write1.ine(,MyApplicationexists);pu
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 23 设计 模式 C# 代码