版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
(面向?qū)ο笤O(shè)計(jì))Part6AspectOrientedProgrammingExample-FigureEditorAfigureconsistsofseveralfigureelements.Afigureelementiseitherapointoraline.FiguresaredrawnonDisplay.ApointincludesXandYcoordinates.Alineisdefinedastwopoints.Example-FigureEditor-DesignDisplayFigureFigureElement*PointLinegetX()getY()getP1setP1setX(int)setY(int)setP1(Point)setP2(Point)2ComponentsareCohesiveLooselyCoupledHavewell-definedinterfaces
(abstraction,encapsulation)CrosscuttingConcern-ExampleDisplayFigureFigureElement*PointLinegetX()getY()getP1setP1DisplayTrackingsetX(int)setY(int)setP1(Point)setP2(Point)2NotifyScreenManagerifafigureelementmovesclassPoint{voidsetX(intx){_x=x;}}classTracer{
staticvoidtraceEntry(Stringstr)
{ System.out.println(str);}staticvoidtraceExit(Stringstr)
{ System.out.println(str);
}}DisplayFigureFigureElement*PointLinegetX()getY()getP1setP1setX(int)setY(int)setP1(Point)setP2(Point)2Tracer
Tracer.traceEntry(“EntryPoint.set”);Tracer.traceExit(“ExitPoint.set”);classLine{voidsetP1(Pointp1{_p1=p1;}}
Tracer.traceEntry(“EntryLine.set”);Tracer.traceExit(“ExitLine.set”);TanglingCodeExample-TracingScatteredConcernCrosscuttingConcernsConcernsthatnaturallytendtobescatteredovermultiplecomponentsConnotbelocalizedintosingleunitscomponents,objects,procedures,functionsIfnotappropriatelycopedwith:ScatteredovermultiplecomponentsTangledcodepercomponentCrosscutting,ScatteringandTanglingCrosscuttingConcernthatinherentlyrelatestomultiplecomponentsResultsinscatteredconcernandtangledcodeScatteringSingleconcernaffectsmultiplemodulesTanglingMultipleconcernsareinterleavedinasinglemoduleTheCostofCrosscuttingConcernsReducedunderstandabilityRedundantcodeinmanyplacesNon-explicitstructureDecreasedadaptabilityHavetofindallthecodeinvolvedHavetobesuretochangeitconsistentlyHavetobesurenottobreakitbyaccidentNewconcernscannotbeeasilyaddedDecreasedreusabilityComponentcodeistangledwithspecifictanglingcodeDecreasedmaintainability‘Rippleeffect’ExampleofCrosscuttingConcernsSynchronizationReal-timeconstraintsError-checkingObjectinteractionconstraintsMemorymanagementPersistencySecurityCachingLoggingMonitoringTestingDomainspecificoptimization...ManycrosscuttingconcernsmayappearinonesystemExample:DistributedSystemDesignComponentinteractionSynchronizationRemoteinvocationLoadbalancingReplicationFailurehandlingQualityofserviceDistributedtransactionsWhattoDo...?HistoricalContextCrosscuttingconcernsarenewtypeofconcernsthathavenotbeen(appropriately)detected/handledbefore.NoexplicitmanagementuntilrecentlyatprogramminglevelNoexplicitconsiderationindesignmethodsNoexplicitconsiderationinprocessNoexplicitconsiderationincasetoolsAspect-OrientedSoftwareDevelopmentProvidesbetterseparationofconcernsbyexplicitlyconsideringcrosscuttingconcerns(aswell)Doesthisbyprovidingexplicitabstractionsforrepresentingcrosscuttingconcerns,i.e.aspectsAndcomposingtheseintoprograms,i.e.aspectweavingoraspectcomposing.AssuchAOSDimprovesmodularityAndsupportsqualityfactorssuchasMaintainability,Adaptability,Reusability,Understandability...ImpactofAOSDonSociety...MITTechnologyReviewlistsAOPasoneofthetop10emergingtechnologiesthatwillchangetheworld–(MITTechnologyReview,January2001)
BasicAOSDTechnologiesCompositionFilters(since1991)UniversityofTwente,TheNetherlandsAspectJ(since1997)XEROXPARC,USDemeterJ/DJ(1993)NortheasternUniversity,USMulti-dimensionalseparationofConcerns/HyperJ(1999)JBossAOPSupportedinJBossAS5AspectJAgeneralpurposeAOprogramminglanguagejustasJavaisageneral-purposeOOlanguageAnintegratedextensiontoJavaacceptsalljavaprogramsasinputoutputs.classfilescompatiblewithanyJVMintegratedwithtoolshttp:///aspectj/classLine{
privatePoint_p1,_p2;PointgetP1(){return_p1;}PointgetP2(){return_p2;}
voidsetP1(Pointp1){
Tracer.traceEntry(“entrysetP1”);_p1=p1;Tracer.traceExit(“exitsetP1”);}
voidsetP2(Pointp2){
Tracer.traceEntry(“entrysetP2”);_p2=p2;Tracer.traceExit(“exitsetP2”);}classPoint{
private
int_x=0,_y=0;
intgetX(){return_x;}
intgetY(){return_y;}
voidsetX(intx){Tracer.traceEntry(“entrysetX”);_x=x;Tracer.traceExit(“exitsetX”)}
voidsetY(inty){Tracer.traceEntry(“exitsetY”);_y=y;Tracer.traceExit(“exitsetY”);}}Example–WithoutAOPTanglingCodeScatteredConcernclassTracer{
staticvoidtraceEntry(Stringstr)
{ System.out.println(str);}
staticvoidtraceExit(Stringstr)
{ System.out.println(str);
}}classLine{
privatePoint_p1,_p2;PointgetP1(){return_p1;}PointgetP2(){return_p2;}
voidsetP1(Pointp1){_p1=p1;}
voidsetP2(Pointp2){_p2=p2;}}classPoint{
private
int_x=0,_y=0;
intgetX(){return_x;}
intgetY(){return_y;}
voidsetX(intx){_x=x;}
voidsetY(inty){_y=y;}}Example–WithAOPaspect
Tracing{
pointcuttraced():call(*Line.*||call(*Point.*);before():traced(){println(“Entering:”+
thisjopinpoint);
void
println(Stringstr){<writetoappropriatestream>}}}AspectisdefinedinaseparatemoduleCrosscuttingislocalizedNoscattering;NotanglingImprovedmodularityAspectLanguageElementsJoinPoint(JP)modelcertainprincipledpointsinprogramexecution
suchasmethodcalls,fieldaccesses,andobjectconstructionMeansofidentifyingJPspickingoutjoinpointsofinterest(predicate)pointcuts:setofjoinpointsMeansofspecifyingbehavioratJPswhathappensadvicedeclarationstheadditionalcodethatyouwanttoapplytoyourexistingmodel.JoinpointsmethodcalljoinpointswhenamethodiscalledmethodreceptionjoinpointswhenanobjectreceivesamessagemethodexecutionjoinpointswhenthebodyofcodeforanactualmethodexecutesfieldgetjointpointwhenafieldisaccessedfieldsetjointpointwhenafieldissetexceptionhandlerexecutionjoinpointwhenanexceptionhandlerexecutesobjectcreationjoinpointwhenaninstanceofaclassiscreatedSomeprimitivepointcutscall(Signature)picksoutmethodorconstructorcallbasedonSignatureexecution(Signature)picksoutamethodorconstructorexecutionjoinpointbasedonSignatureget(Signature)picksoutafieldgetjoinpointbasedonSignatureset(Signature)picksoutafieldsetjoinpointbasedonSignaturehandles(TypePattern)picksoutanexceptionhandlerofanyoftheThrowabletypesofTypePatterninstanceOf(ClassName)picksoutjoinpointsofcurrentlyexecutingobjectsofclassClassNamewithin(ClassName)picksoutjoinpointsthatareincodecontainedinClassNamewithinCode(Signature)picksoutjoinpointswithinthememberdefinedbymethororconstructor(Signature)cflow(pointcut)picksoutallthejoinpointsinthecontrolflowofthejoinpointspickedoutbythepointcutAdvicePieceofcodethatattachestoapointcutandthusinjectsbehavioratalljoinpointsselectedbythatpointcut.example:before(args):pointcut
{Body}wherebeforerepresentsabeforeadvicetype(seenextslide).CantakeparameterswithpointcutsAdviceTypesAdvicecodeexecutesbefore,codeisinjectedbeforethejoinpointbefore(args):pointcut
{Body}after,codeisinjectedafterthejoinpoint
after(args):pointcut
{Body}around,codeisinjectedaround(inplaceof)codefromjoinpointReturnTypearound(args):pointcut
{Body}JPAdviceJPAdviceAdviceJPAspectAmodularunitofcross-cuttingbehavior.Likeaclass,canhavemethods,fields,initializers.canbeabstract,inheritfromclassesandabstractaspectsandimplementinterfaces.encapsulatespointcutsandadvicescanintroducenewmethods/fieldstoaclassAspectXAspectYclassXAspectYAspectXclassYxclassLine{
privatePoint_p1,_p2;PointgetP1(){return_p1;}PointgetP2(){return_p2;}
voidsetP1(Pointp1){_p1=p1;}
voidsetP2(Pointp2){_p2=p2;}}classPoint{
private
int_x=0,_y=0;
intgetX(){return_x;}
intgetY(){return_y;}
voidsetX(intx){_x=x;}
voidsetY(inty){_y=y;}}Example-AspectJaspect
Tracing{pointcuttraced():call(*Line.*||call(*Point.*);before():traced(){println(“Entering:”+
thisjopinpoint);
after():traced(){println(“Exit:”+
thisjopinpoint);
void
println(St
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 負(fù)面情緒處理課程設(shè)計(jì)
- 2024年幼兒健康管理知識(shí)培訓(xùn)題庫(kù)(含答案)
- 二零二五版四荒地承包經(jīng)營(yíng)權(quán)投資融資合同3篇
- 年度多用客房車(chē)市場(chǎng)分析及競(jìng)爭(zhēng)策略分析報(bào)告
- 年度垃圾收轉(zhuǎn)裝備戰(zhàn)略市場(chǎng)規(guī)劃報(bào)告
- 2024版遠(yuǎn)程教育平臺(tái)搭建合同3篇
- 二零二五年度門(mén)店租賃合同范本:環(huán)保節(jié)能標(biāo)準(zhǔn)版4篇
- 室外電氣工程施工方案
- 送水泵房的課程設(shè)計(jì)
- 2025年度個(gè)人電子設(shè)備買(mǎi)賣(mài)合同模板2篇
- 《面神經(jīng)炎護(hù)理措施分析》3900字(論文)
- 城市微電網(wǎng)建設(shè)實(shí)施方案
- 企業(yè)文化融入中華傳統(tǒng)文化的實(shí)施方案
- 9.1增強(qiáng)安全意識(shí) 教學(xué)設(shè)計(jì) 2024-2025學(xué)年統(tǒng)編版道德與法治七年級(jí)上冊(cè)
- 《化工設(shè)備機(jī)械基礎(chǔ)(第8版)》全套教學(xué)課件
- 人教版八年級(jí)數(shù)學(xué)下冊(cè)舉一反三專(zhuān)題17.6勾股定理章末八大題型總結(jié)(培優(yōu)篇)(學(xué)生版+解析)
- 2024屆上海高考語(yǔ)文課內(nèi)古詩(shī)文背誦默寫(xiě)篇目(精校版)
- DL-T5024-2020電力工程地基處理技術(shù)規(guī)程
- 初中數(shù)學(xué)要背誦記憶知識(shí)點(diǎn)(概念+公式)
- 駕照體檢表完整版本
- 農(nóng)產(chǎn)品農(nóng)藥殘留檢測(cè)及風(fēng)險(xiǎn)評(píng)估
評(píng)論
0/150
提交評(píng)論