欢迎来到天天文库
浏览记录
ID:40199666
大小:605.87 KB
页数:36页
时间:2019-07-25
《Design Patterns 设计模式》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、2012/11/19Monday设计模式分类标准1设计模式有两种分类标准,按用途来分:2按scope来分,主要分成类模式和对象模式两类。a)类模式处理类和其子类之间的关系,这种关系一般是通过继承实现的,因此在编译时就已经确定。b)对象模式处理对象间的关系,这种关系可在运行时修改,更灵活。c)因为大部分的模式都用到了继承,因此只有少数几个模式被认为是类模式。Classpatternsdealwithrelationshipsbetweenclassesandtheirsubclasses.Theserelationshipsareestablishedthroughinheritan
2、ce,sotheyarestatic—fixedatcompile-time.Objectpatternsdealwithobjectrelationships,whichcanbechangedatrun-timeandaremoredynamic.Almostallpatternsuseinheritancetosomeextent.Sotheonlypatternslabeled"classpatterns"arethosethatfocusonclassrelationships.NotethatmostpatternsareintheObjectscope.3Anobje
3、ctpackagesbothdataandtheproceduresthatoperateonthatdata.Theproceduresaretypicallycalledmethodsoroperations.Anobjectperformsanoperationwhenitreceivesarequest(ormessage)fromaclient.1Requestsaretheonlywaytogetanobjecttoexecuteanoperation.Operationsaretheonlywaytochangeanobject'sinternaldata.Becau
4、seoftheserestrictions,theobject'sinternalstateissaidtobeencapsulated;itcannotbeaccesseddirectly,anditsrepresentationisinvisiblefromoutsidetheobject.2面向对象设计的难点:decomposingasystemintoobjects,可考虑的因素太多,又没有唯一合适的标准。3Manyobjectsinadesigncomefromtheanalysismodel.Butobject-orienteddesignsoftenendupwith
5、classesthathavenocounterpartsintherealworld.Someofthesearelow-levelclasseslikearrays.Othersaremuchhigher-level.Forexample,theComposite(183)patternintroducesanabstractionfortreatingobjectsuniformlythatdoesn'thaveaphysicalcounterpart.Strictmodelingoftherealworldleadstoasystemthatreflectstoday'sr
6、ealitiesbutnotnecessarilytomorrow's.Theabstractionsthatemergeduringdesignarekeytomakingadesignflexible.4Everyoperationdeclaredbyanobjectspecifiestheoperation'sname,theobjectsittakesasparameters,andtheoperation'sreturnvalue.Thisisknownastheoperation'ssignature.Thesetofallsignaturesdefinedbyanob
7、ject'soperationsiscalledtheinterfacetotheobject.5Atypeisanameusedtodenoteaparticularinterface.6Therun-timeassociationofarequesttoanobjectandoneofitsoperationsisknownasdynamicbinding.7,dynamicbindingletsyousubstituteobjectsthathaveidenti
此文档下载收益归作者所有