軟件體系結(jié)構(gòu)-3設(shè)計模式visitor_第1頁
軟件體系結(jié)構(gòu)-3設(shè)計模式visitor_第2頁
軟件體系結(jié)構(gòu)-3設(shè)計模式visitor_第3頁
軟件體系結(jié)構(gòu)-3設(shè)計模式visitor_第4頁
軟件體系結(jié)構(gòu)-3設(shè)計模式visitor_第5頁
已閱讀5頁,還剩67頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

設(shè)計模1內(nèi)容簡設(shè)設(shè)計模式概設(shè)設(shè)計模式的描實(shí)例研究:實(shí)例研究:Visitor2設(shè)計模式概ChristopherAlexander:“每一個模式描述了 3設(shè)計模式的四個基本要模式名稱(Pattern一個解決方案問題描述了應(yīng)該在何時使解決方案描述了設(shè)計的組成部分,它們之間的相互關(guān)系各自的職責(zé)和協(xié)作方式效果45問題學(xué)校有教師和工 問題學(xué)校有教師和工eclassclass{ privateintpublicstring{get{returnname;set{name=value;}public{get{ee;set e=value;}publicint{set{vacationDays=value;}}問題classclassTeacher:{publicTeacher(stringname,{Name=e,inte VacationDays=}}classEngineer:{publicEngineer(stringname,{Name=e,inte VacationDays=}}問題staticvoidMain(string[]{Teacherzhangsan=new ",2500.0,Engineer =new ",3500.0, e假期是Console.Wriine(lisi.Name+"的收入是"+ e+",假期是"+lisi.VacationDays);}如何批量主要內(nèi)1模1模式動機(jī)與2模式結(jié)構(gòu)與3模式實(shí)例與4模式效果與應(yīng)者模式模式模式名稱:者模式對于系統(tǒng)中的某些對象,它們在同一個集合中可以接受一類稱為者的對象來,而且不同的者其方式有所不同,者模式為解決者模式模式 者模式模式 的類的前提下定義作用于這些元素的新操作。者模式結(jié)

者模式

者模式 者模式

問題class{privatestringname;privatedouble publicstring{get{returnname;}set{name=value;}}public {get{return e;}set e=value;}publicint{get{returnvacationDays;}set{vacationDays=value;}}}問題classclassTeacher:{{Name=e,inte }{}}classEngineer:{{Name=e,inte }publicoverridevoidAccept(Visitor{}}者模式class{} eVisitor:{{e*= }}{{ }}者模式class{privateArrayListemployees=newpublicvoidAttach(Employee{}publicvoidDetach(Employee{}publicvoidAccept(Visitor{foreach(Employeeein}}者模式staticvoidMain(string[]{Teacherzhangsan=new ",2500.0,Engineer =new ",3500.0,Employeese=newEmployees();eVisitorv1=new VacationVisitorv2=newVacationVisitor();}者模式模式

者模式classclass{//publicvoidAccept(Visitor}者模式classclassConcreteElementA:{//overridepublicvoidAccept(Visitor{}publicvoid{}}classConcreteElementB:{//overridepublicvoidAccept(Visitor{}publicvoid{}}者模式class{//privateArrayListelements=new//publicvoidAttach(Element{}publicvoidDetach(Element{}publicvoidAccept(Visitor{foreach(Elementeinelements)}}者模式classclass{//publicvoidConcreteElementAconcreteElementA);publicvoidVisitConcreteElementB(ConcreteElementB}者模式classclassConcreteVisitor1:{//overridepublicvoidConcreteElementA{ ine("{0}visitedby{1}",concreteElementA,this);}overridepublicvoidConcreteElementB{ ine("{0}visitedby{1}",concreteElementB,this);}}者模式classclassConcreteVisitor2:{//overridepublicvoidConcreteElementA{ ine("{0}visitedbyconcreteElementA,}overridepublicvoidConcreteElementB{ ine("{0}visitedby{1}",concreteElementB,this);}}者模式staticvoidMain(string[]{//SetupObjectStructureo=newObjectStructure();o.Attach(newConcreteElementA());o.Attach(newConcreteElementB());//CreatevisitorConcreteVisitor1v1=newConcreteVisitor1();ConcreteVisitor2v2=new//Structureacceptingvisitors}者模式者模式的優(yōu) ,增加新的操作會很復(fù)雜。而使用者模式,增加新的操作就意味著增加一個新的者類,因此將變者模式將有關(guān)的行為集中到一個者對象中,者模式可以跨過幾個類的等級結(jié) 者模式者模式的缺破壞封裝。者模式要求者對象并調(diào)用每的要求:它們必須一些自己的操作和內(nèi)部狀態(tài)。不然,者的就變得沒有意義。由于者對象自己會積累操作所需的狀態(tài),從而使這些狀態(tài)不再在節(jié)點(diǎn)對象中,這也是破壞封裝的。增加新的節(jié)點(diǎn)類變得很。每增加一個新的節(jié)點(diǎn)都意味著要在抽象者角色中增加一個新的抽象操作,并在每一個具體者類中增加相應(yīng)的具體操作。者模式模式模式應(yīng)

者模式 以供不 體元素。相同的者可以以不同的方式不同的元素,相同的元素可以接受不同者以不同方式。在者模式中,增加新的者無須修改原有系統(tǒng)者模式模式–者模式的主要優(yōu)點(diǎn)在于使得增加新的操作變得很容易,將有關(guān)元素對象的行為集中到一個訪以跨過類的等級結(jié)構(gòu)屬于不同的等級結(jié)構(gòu)的元素元素類很,而且在一定程度上破壞系統(tǒng)的封裝性。Visitor模式常見用 Avariableisliveataparticularpointintheprogramifitsvalueatthatpointwillbeusedinthefuture(dead,otherwise).

LivenessatTwoMore–Avariableislive-outatanodeifitisliveonanyofthatnode’sout-edges–Avariableislive-inatanodeifitisliveonanyofthatnode’sin-edges publicstaticvoidmain(String[]args)for(Stringname:args)Noderesult=if(result!=null&&resultinstanceofStatement)PerformGenKillpgnew newStackWorklist(),new

//pgnewPerformGenKill<AvailableExpression ArithmeticExpression>(newStackWorklist(),new publicinterfaceWorklistvoidadd(NodeNode}publicinterface ysis<T>ImmutableSet<T>getGen(NodeImmutableSet<T>getKill(NodeImmutableSet<T>ImmutableSet<T>ImmutableSet<T>ImmutableSet<T>}publicclassLiveVariable ysis<Variable>{publicImmutableSet<Variable>getGen(Nodenode)finalList<Variable>l=newArrayList<Variable>publicVoidvisit(UseVariableuv)return}returnnew}publicImmutableSet<Variable>getKill(Nodenode)finalList<Variable>l=newArrayList<Variable>publicVoidvisit(AssignStatementas)return}returnnew}publicImmutableSet<Variable>getInitial()returnnew}return}publicbooleanisReverse()return}}publicclassPerformGenKill<Lextends intpublicFlowGraphfg=newWorklist Map<Node,ImmutableSet<T>>stateofentry=newHashMap<Node,ImmutableSet<T>>(); Map<Node,ImmutableSet<T>>stateofexit=newHashMap<Node,ImmutableSet<T>>();Statement ysis)this.list= ysis publicbooleanlineNotEmpty(Stringintcolumnnum)int}return}

returnImmutableSet<T>getEntryResult(Nodenode)return ImmutableSet<T>getExitResult(Nodenode)return publicStringwriteOneLine(Stringfinalintcolumnnum,finalintrankwidth)String Stringwritecolumn=int }else{writecolumn=column[j];column[j]="“;retval+=retval+=' retval+= returnretval; voidrun(Statementroot)this.root=root;Expressions.aes.clear();numofiteration= ysis.isRev

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論