webeginbydeninganotionofmodularreasoningthatcorrespondstoParnasscomprehensibilitybenetModularreasoningistheprocessofunderstandingasystemorprovingpropertiesaboutitonemoduleatatimeAlanguagesuppo ID: 387352
Download Pdf The PPT/PDF document "Obliviousness,ModularReasoning,andtheBeh..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Obliviousness,ModularReasoning,andtheBehavioralSubtypingAnalogyCurtisCliftonandGaryT.Leavens1IowaStateUniversity,226AtanasoHall,AmesIA50011,USA,fcclifton,leavensg@cs.iastate.edu,WWWhomepage:http://www.cs.iastate.edu/~fcclifton,leavensgAbstract.TheobliviousnesspropertyofAspectJ-likelanguagescon- ictswiththeabilitytoreasonaboutprogramsinamodularfashion.Thiscanmakedebuggingandmaintenancedicult.Inobject-orientedprogramming,thedisciplineofbehavioralsubtypingallowsonetoreasonaboutprogramsmodularly,despitetheobliviousna-tureofdynamicbinding;however,itisnotclearwhatdisciplinewouldhelpprogrammersinAspectJ-likelanguagesobtainmodularreasoning.Behavioralsubtypingwasbornoutofthestoriesprogrammersweretellingintheirobject-orientedprogramsandhowtheyreasonedaboutthem.ProgrammersuseAspectJ-likelanguagestotellwhatwecall\su-perimposition"and\adaptation"stories.Thus,adisciplineofmodularreasoningforanAspectJ-likelanguagemustaccountforbothsortsofstories.WedescribethemodularreasoningproblemforAspectJ-likelanguages.Wedonotyethaveasolution,butconciselyarticulatetheissuesinvolved.1IntroductionMuchoftheworkonaspect-orientedprogramminglanguagesreferstotheworkofParnas[31].Parnasarguesthatthemodulesintowhichasystemisdecom-posedshouldprovidebenetsinthreeareas(p.1054):Thebenetsexpectedofmodularprogrammingare:1.managerial|developmenttimeshouldbeshortenedbecausesepa-rategroupswouldworkoneachmodulewithlittleneedforcommu-nication;2.product exibility|itshouldbepossibletomakedrasticchangestoonemodulewithoutaneedtochangeothers;3.comprehensibility|itshouldbepossibletostudythesystemonemoduleatatime.Thewholesystemcanthereforebebetterdesignedbecauseitisbetterunderstood.Itseemsclearthataspect-orientedlanguagesprovidemanybenetsrelatedtoParnas'ssecondpoint[13,18].Amongthesebenetsareareductionintangling webeginbydeninganotionofmodularreasoningthatcorrespondstoParnas'scomprehensibilitybenet.Modularreasoningistheprocessofunderstandingasystem(orprovingprop-ertiesaboutit)onemoduleatatime.AlanguagesupportsmodularreasoningiftheactionsofamoduleMwritteninthatlanguagecanbeunderstoodbasedsolelyonthecodecontainedinMandthecodesurroundingM,alongwiththesignatureandbehaviorofanymodulesreferredtobythatcode.Thenotionofamoduleandthesurroundingcodeforamodulearedeterminedbytheprogram-minglanguage.InJava,wemightconsideracompilationunittobeamodule,andinstandardJavanocodesurroundsamodule3.Code,C,referstoamoduleNifCexplicitlynamesN,ifCislexicallynestedwithinN,orifNisastandardmoduleinaxedplace(suchasObjectinJava).Weusecontractstospecifythecode'sbehavior.Inthemostconcretecase,thecontractisthemethod'scode,butweprefertothinkofmoreabstractcontracts.Thesecanbewritteninaformalspecicationlanguage[21,25],orinformallybywritingcommentssuchas\Thismethodreturnstrueifthegivenleexists".Ourinterestinmodularreasoninginaspect-orientedprogramminglanguagesismotivatedinpartbyourinitialworkoncombiningMultiJava[6,8]andJML[21].3TheProblem:UndisciplinedObliviousnessIntypicalobject-orientedlanguages,thedynamictypeofthereceiverobjectisusedtoselecttheappropriatemethodtoinvokeforagivenmessagesend.Suchdynamicselectionofthetargetmethodcanpreventmodularreasoning.Forexample,considerthedeclarationofPointinFigure1anditsmethod,move.The//@-commentsbeforemove'sdeclarationgiveitsbehavioralspecicationinJML.{Theclause\requirestrue"saysthatclientsarenotobligedtoestablishanyprecondition.{Theclause\assignablepos"saysthattheposeldofthereceiverobjectmaybechangedbythemethod,butnotanyotherlocations.{Theclause\ensures..."saysthat,aftermovereturns,thevaluereturnedbygetPos()isequaltothesumofthedistargumentandthevaluereturnedbygetPos()beforemovewascalled.SupposeanobjectofstatictypePointispassedtoamethodclient,asinFigure2.Ifmodularreasoningissound,thentheprogrammercanreasonabouttheinvocationofmovebasedonitsspecicationinPoint.Thatis,iftherstassertioninFigure2holds,thenthesecondassertionisvalidbasedonthespecicationofPoint'smovemethod.Thedenitionofmodularreasoning 3Anotherinterpretationof\module"and\surroundingcode"inJavamightbethatatypedeclarationisamodule,and,fornestedtypedeclarations,thecodefortheenclosingtypedeclarationisthesurroundingcode. requiresthattheprogrammershouldnothavetoconsiderpossiblesubtypesofPointwhendoingthisreasoning,sincetheyarenotmentionedintheclientcode.However,bysubsumption,aninstanceofanunseensubtypeofPoint,sayRightMovingPoint,maybepassedtoclient.Whatif(asinFigure3)RightMovingPointoverridesmethodmove,buttheoverridedoesnotsatisfythespecicationofmoveinPoint?Thenmodularreasoningsuchasthatdescribedforclientisnotvalid.UsingFigure3,aftertheclient'sinvocationofp.move(-10),p.getPos()returns10,not-10asasserted.Theconceptofbehavioralsubtypingrestoressoundmodularreasoningbyim-posingthespecicationofPointonallitssubtypes[11,22,24].Thus,RightMov-ingPointdoesnotcorrectlyimplementabehavioralsubtypeofPoint,becauseitsimplementationdoesnotsatisfythespecicationofmoveinPoint.Behavioralsubtypingisoftendescribedbysayingthatthebehaviorofasubtypeshouldnotbesurprising,withrespecttothespeciedbehaviorofasupertype.publicclassRightMovingPointextendsPointfpublicvoidmove(intdist)fif(dist0)super.move(-dist);elsesuper.move(dist);ggFig.3.ARightMovingPointclassAspointedoutbyFilmanandFriedman[14],subtypingwithsubsumption,asabove,isanexampleofobliviousness.Aspect-orientedprogramminglanguagesallowprogrammersmuchgreaterlatitudeindeningobliviousbehaviors.3.1Non-modularReasoninginAspectJNextweshowthat,justasmodularreasoningisnotageneralpropertyofobject-orientedprogramminglanguagesintheabsenceofbehavioralsubtyping,modularreasoningisnotageneralpropertyofAspectJ.Wedothisbyconsideringanaspect-orientedextensiontoourPointexample.Figure4givesanaspect,MoveLimiting,thatmodiesthebehaviorofPointinstancesinthesamewayasRightMovingPoint.MoveLimitingdeclaresapieceofaround-advice.ThisadviceinterceptscallstoPoint'smovemethod.Ifthear-gumentpassedtotheclientisnegative,then,justasinRightMovingPoint,controlproceedstoPoint'smovemethodwiththeparametersettotheabsolutevalueoftheoriginalparameter.AswithRightMovingPoint,theclientpro-grammer'sreasoning,asindicatedbytheassertstatementsinFigure2,isnotcorrectinthepresenceoftheMoveLimitingaspect. storiesareanalogoustothestoriestoldwithsubtypesinobject-orientedlan-guages;bothseektoenhanceexistingbehaviorwithoutintroducingsurprisingbehavior.Inthebehavioralsubtypingliterature,notintroducing\surprisingbehavior"meansthatanoverridingmethodcannotcontradictthespeciedbehaviorofthemethoditoverrides.Suchmethodscan,however,introducenewbehaviorinar-easthatareunspeciedinthesupertype.Theclassicexampleisthespecicationofadrawmethodforshapes.ThemethodisunderspeciedintheShapesuper-type,whichallowsoverridingmethodsinRectangleandCircletospecializeitsbehaviorinappropriateways.Onewaytothinkaboutbehavioralsubtypingisthatanoverridingmethodinheritsthespecicationofthesupertypemethodthatitoverrides[12].Thisforcestheoverridingmethodtoobeythesupertype'sspecication.Inanas-pectdesignedforsuperimposition,theanalogousrequirementwouldbethattheadvicemustobeythespecicationsofthecodethatitadvises.AdaptationStoriesAdaptationstoriesareaboutmodifyingthebehaviorofexistingprogramswithoutchangingtheircode.Thesestoriescomeintwostyles:{Localadaptationstoriesareaboutchangingthebehaviorofasubsetofaprogramasviewedbyotherclientcodewithintheprogram.Anexampleoflocaladaptationisanaspectforpersistence,wheresomecodemustexplicitlyestablishlinkstoadatabasewhiletheremainderoftheprogrambenetsfrompersistencewithoutanyexplicitchangestoitscode[32].{Globaladaptationstoriesareaboutchangingthebehaviorofanentirepro-gramasviewedbyusersoftheprogram.Forexample,usinganaspecttoaddauthenticationtoanexistingwebserverwouldbeaglobaladaptationstory[19][20,Ch.10].Globaladaptationsaredistinguishedinthatnopartoftheadaptedprogramreliesonthepresenceoftheadaptation.Incontrasttoaspectsdesignedforsuperimposition,programmersexpectaspectsdesignedforadaptationtochangethebehaviorofthemodulestheyadvise.Adaptationstoriescanbetoldinobject-orientedlanguages.Sometimesthisisdoneusingsubclassing,butthisviolatesthebehavioralsubtypingdisciplineandisgenerallydiscouraged[5,pp.71{77][23,26].Instead,therecommendedapproachistouseawrapperclasswhoseinstancescontainareferencetotheobjecttobeadapted[15,pp.139{150,175{184].Thespecierofthewrapperclass\startsfromscratch";shecanprovidewhateverbehaviorisneeded,inde-pendentoftheoriginalclass'sspecication.Thiswrapperapproachsacricestheobliviousnessofdynamicbindingtoachievemodularreasoning;aclientofthewrapperclasscanreasonusingthewrapperclass'sspecication.Itmaybethecasethatasimilarsacriceofobliviousnessisneededformodularreasoninginaspect-orientedprogramminglanguages.Likethewrappedclass,theadaptedcodecouldremainoblivioustotheadaptationaspect.Butlikethecodethatusesthewrapperclass,perhapsthecodethatreliesonthe 4.2DataRestrictionsAcomplementaryintermediateapproachistorestrictthedatathatmaybemod-iedbyadvice.Thisisexempliedinobject-orientedprogramminglanguagesbytheworkonvariousownershiptypesystems[2,27{29].Thesetypesystemsareprimarilyconcernedwithrestrictingaliasingtopromotedataencapsulation,andhencemodularreasoning.AnanalogousapproachforAspectJ-likelanguagesmightbetolimitthestatethatmaybemutatedbyadvicetojustthatstatethatitowns.Suchalimitationisstaticallycheckable,butrequiresadditionalannotationsinthesourcecode.However,theseannotationoertheadditionalbenetofcontrollingsomeeectsofaliasing.5SummaryandFutureWorkThereisaparallelbetweentheobliviousnessofdynamicbindinginobject-orientedlanguagesandthatofadvicebindinginaspect-orientedlanguages[14].Wehaveshownthatthisparallelprovokesausefulanalogybetweenreasoninginthetwostyles.Wehavedemonstratedthatbothsortsofobliviousnesscanpreventmodularreasoning,asdemonstratedbytheMoveLimitingaspectandthe(non-behavioral)subtypeRightMovingPoint.Behavioralsubtypingaddsmodularreasoningtoobject-orientedprogram-minglanguages.TheproblemistondasimilarprogrammingdisciplineforAspectJ-likelanguages.Wehavedescribedtwosortsofstoriesthatprogram-merstellabouthowtheyuseAspectJ:superimpositionandadaptationstories.Thesestoriesprovideconstraintsonsolutionstothemodularreasoningproblem,inthatacompletelyviablesolutionshouldsupportbothkinds.Thebehavioralsubtypinganalogyseemstobearichoneforthinkingabouttherelationshipbetweenobject-orientedlanguagesandAspectJ-likelanguages.Despitetheabsenceofasolutiontothemodularreasoningproblem,wehopethatotherresearcherswillbenetfromthebehavioralsubtypinganalogy.Su-perimpositionandadaptationstoriesseemtocharacterizehowaspect-orientedprogramminglanguagesareactuallyused.Wehopethatthischaracterizationwillprovideusefulconstraintsinthedesignofnewaspect-orientedlangaugesandreasoningmechanisms.Inadditiontoconsideringwhatbehavioralsubtypingmaysayaboutaspect-orientedprogramming,itmightbeinterestingtoconsiderwhethertheanalogyworksinreverse.Canaspect-orientedprogrammingprovidenewinsightontheearlierworkonobject-orientedlanguages?Ourfutureworkistoformalizethemodularreasoningproblemandinvesti-gatethesolutionspacebybuildingacorecalculusforanAspectJ-likelanguagewithsupportformodularreasoning.Ourinitialstepstowardsthiscalculusareavailableinatechnicalreport[9],thoughthatworkdoesnotincludemodular-ityfeatures.Ournextstepistoextendthecalculuswithsuchfeatures.Afterprovingtheappropriatemodularityproperties,wewillthenextendthecalculustoafull-scaleprogramminglanguage. Europeansoftwareengineeringconferenceheldjointlywith9thACMSIGSOFTsymposiumonFoundationsofsoftwareengineering,Vienna,Austria.11.K.K.DharaandG.T.Leavens.Weakbehavioralsubtypingfortypeswithmutableobjects.InS.Brookes,M.Main,A.Melton,andM.Mislove,editors,MathematicalFoundationsofProgrammingSemantics,EleventhAnnualConference,volume1ofElectronicNotesinTheoreticalComputerScience.Elsevier,1995.Availablefromhttp://www.elsevier.nl/locate/entcs/volume1.html.12.K.K.DharaandG.T.Leavens.Forcingbehavioralsubtypingthroughspecicationinheritance.InProceedingsofthe18thInternationalConferenceonSoftwareEn-gineering,Berlin,Germany,pages258{267.IEEEComputerSocietyPress,Mar.1996.AcorrectedversionisIowaStateUniversity,Dept.ofComputerScienceTR#95-20c.13.T.Elrad,R.E.Filman,andA.Bader.Aspect-orientedprogramming:Introduction.Commun.ACM,44(10):29{32,Oct.2001.14.R.E.FilmanandD.P.Friedman.Aspect-orientedprogrammingisquanticationandobliviousness.InM.Aksit,S.Clarke,T.Elrad,andR.E.Filman,editors,Aspect-OrientedSoftwareDevelopment.Addison-Wesley,Reading,MA,toappear.15.E.Gamma,R.Helm,R.Johnson,andJ.Vlissides.DesignPatterns:ElementsofReusableObject-OrientedSoftware.Addison-Wesley,Reading,Mass.,1995.16.J.Gosling,B.Joy,G.Steele,andG.Bracha.TheJavaLanguageSpecicationSecondEdition.TheJavaSeries.Addison-Wesley,Boston,Mass.,2000.17.G.Kiczales,E.Hilsdale,J.Hugunin,M.Kersten,J.Palm,andW.Griswold.GettingstartedwithAspectJ.Commun.ACM,44(10):59{65,Oct.2001.18.G.Kiczales,E.Hilsdale,J.Hugunin,M.Kersten,J.Palm,andW.G.Griswold.AnoverviewofAspectJ.InJ.L.Knudsen,editor,ECOOP2001|Object-OrientedProgramming15thEuropeanConference,BudapestHungary,volume2072ofLec-tureNotesinComputerScience,pages327{353.Springer-Verlag,Berlin,June2001.19.I.Kiselev.Aspect-OrientedProgrammingwithAspectJ.SamsPublishing,Indi-anapolis,2003.20.R.Laddad.AspectJinAction.ManningPublicationsCo.,Grennwich,Conn.,2003.21.G.T.Leavens,A.L.Baker,andC.Ruby.PreliminarydesignofJML:AbehavioralinterfacespecicationlanguageforJava.TechnicalReport98-06t,IowaStateUniversity,DepartmentofComputerScience,June2002.Seewww.jmlspecs.org.22.G.T.LeavensandW.E.Weihl.Reasoningaboutobject-orientedprogramsthatusesubtypes(extendedabstract).InN.Meyrowitz,editor,OOPSLAECOOP'90Proceedings,volume25(10)ofACMSIGPLANNotices,pages212{223.ACM,Oct.1990.23.B.LiskovandJ.Guttag.ProgramDevelopmentinJava.TheMITPress,Cam-bridge,Mass.,2001.24.B.LiskovandJ.Wing.Abehavioralnotionofsubtyping.ACMTrans.Prog.Lang.Syst.,16(6):1811{1841,Nov.1994.25.B.Meyer.Eiel:TheLanguage.Object-OrientedSeries.PrenticeHall,NewYork,NY,1992.26.B.Meyer.Object-orientedSoftwareConstruction.PrenticeHall,NewYork,NY,secondedition,1997.27.P.Muller.ModularSpecicationandVericationofObject-OrientedPrograms,volume2262ofLectureNotesinComputerScience.Springer-Verlag,2002.Theauthor'sPh.D.Thesis.Availablefromhttp://www.informatik.fernuni-hagen.de/import/pi5/publications.html.