软件设计模式-体系结构-PPT讲稿 0-Software-Design-Patterns-20121030 lec1_FactoryMethod-Creational.ppt

软件设计模式-体系结构-PPT讲稿 0-Software-Design-Patterns-20121030 lec1_FactoryMethod-Creational.ppt

ID:51968220

大小:500.00 KB

页数:64页

时间:2020-03-26

软件设计模式-体系结构-PPT讲稿 0-Software-Design-Patterns-20121030 lec1_FactoryMethod-Creational.ppt_第1页
软件设计模式-体系结构-PPT讲稿 0-Software-Design-Patterns-20121030 lec1_FactoryMethod-Creational.ppt_第2页
软件设计模式-体系结构-PPT讲稿 0-Software-Design-Patterns-20121030 lec1_FactoryMethod-Creational.ppt_第3页
软件设计模式-体系结构-PPT讲稿 0-Software-Design-Patterns-20121030 lec1_FactoryMethod-Creational.ppt_第4页
软件设计模式-体系结构-PPT讲稿 0-Software-Design-Patterns-20121030 lec1_FactoryMethod-Creational.ppt_第5页
资源描述:

《软件设计模式-体系结构-PPT讲稿 0-Software-Design-Patterns-20121030 lec1_FactoryMethod-Creational.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、Lecture1TheFactoryMethodPattern工厂方法模式有的工厂生产飞机,有的工厂生产汽车,听说过有生产类的对象的工厂吗?本讲讲述的工厂方法模式专门生产对象。1ContentsofthislectureIntroductionofthefactorymethodpatternTheoryofthesimplefactorymethodPatternanddesignexamplesTheoryofthefactorymethodpatternanddesignexamplesFurtherdiscus

2、sionofthefactorymethodpattern2IntroductionoftheFactoryMethodPattern3IntroductiontoFactoryMethodPattern问题:怎样调用类中的一个方法?Howtoinvokeamethodinaclass?Ifanapplicationobjectknowstheexactmethoditneeds,itcandirectlyinstantiatetheclassfromtheclasshierarchythatcontainstheme

3、thod.Seeexamplebelow.4Car+buyCar()+buyParts()Lincoln+buyCar()+buyParts()Cadillac+buyCar()+buyParts()Buick+buyCar()+buyParts()ClientobCar:CarMain()ClientObjectDirectlyAccessingaClassHierarchyIntroductiontoFactoryMethodPatternCarmyCar;myCar=newLincoln();myCar.buyC

4、ar();5新的情况:1)如果一个类的结构有很多子类2)你不知道该准确地调用哪一个怎么办呢???IntroductiontoFactoryMethodPattern6Question:Howtoinvokeamethodinaclasshierarchythatcontainsmanysubclassesandyoudon’tknowexactlywhichonetoselect?Thechoicemaydependon:运行状态.Thestateoftherunningapplication(inputfromuse

5、rs)应用配置设置.ApplicationconfigurationsettingsInsuchcases,anapplicationobjectneedstouseconditionalstatementstoinstantiateanappropriateclassfromthehierarchytoaccessitsservicesIntroductiontoFactoryMethodPattern7Anapplicationobjectneedstoimplementtheclassselectioncrite

6、riatoinstantiateanappropriateclassfromthehierarchytoaccessitsservicesClientobCar:CarMain()If(usrChoice==1){obCar=newLincoln(model);obCar.buyCar();}elseif(usrChoise==2){obCar=newCadillac(model)obCar.buyCar();}Car+buyCar()+buyParts()Lincoln+buyCar()+buyParts()Cadi

7、llac+buyCar()+buyParts()Buick+buyCar()+buyParts()IntroductiontoFactoryMethodPattern8该设计的缺点:Thistypeofdesignhasthefollowingdisadvantages:Highcoupling(高耦合).Becauseeveryapplicationobjectthatintendstousetheservicesofferedbytheclasshierarchyneedstoimplementtheclassse

8、lectioncriteria,itresultsinahighdegreeofcouplingbetweenanapplicationobjectandtheserviceproviderclasshierarchy.IntroductiontoFactoryMethodPattern9Inelegantstatement(难看

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。