版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
(面向?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. 本站所有資源如無特殊說明,都需要本地電腦安裝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)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年工業(yè)自動化生產(chǎn)線廠房租賃合同4篇
- 2024離婚合同書:不含財(cái)產(chǎn)分割案例版B版
- 個(gè)人房產(chǎn)抵押合同
- 2024年04月交通銀行股份有限公司畢節(jié)分行(貴州)招考1名勞務(wù)人員筆試歷年參考題庫附帶答案詳解
- 2024物業(yè)公司收費(fèi)標(biāo)準(zhǔn)合同
- 2025年度不銹鋼復(fù)合材料應(yīng)用研發(fā)與推廣協(xié)議3篇
- 2024年03月貴州中國農(nóng)業(yè)銀行貴州省分行春季招考筆試歷年參考題庫附帶答案詳解
- 2025年度農(nóng)產(chǎn)品溯源體系建設(shè)合作協(xié)議范本3篇
- 二零二五年度草牧場資源綜合利用與承包合同3篇
- 專職護(hù)林員2024年度服務(wù)協(xié)議版B版
- 骨科手術(shù)后患者營養(yǎng)情況及營養(yǎng)不良的原因分析,骨傷科論文
- GB/T 24474.1-2020乘運(yùn)質(zhì)量測量第1部分:電梯
- GB/T 12684-2006工業(yè)硼化物分析方法
- 定崗定編定員實(shí)施方案(一)
- 高血壓患者用藥的注意事項(xiàng)講義課件
- 特種作業(yè)安全監(jiān)護(hù)人員培訓(xùn)課件
- (完整)第15章-合成生物學(xué)ppt
- 太平洋戰(zhàn)爭課件
- 封條模板A4打印版
- T∕CGCC 7-2017 焙烤食品用糖漿
- 貨代操作流程及規(guī)范
評論
0/150
提交評論