CMU CS 15819 - A Formal Model of Modularity in Aspect-Oriented Programming

Unformatted text preview:

A Formal Model of Modularity in Aspect-Oriented ProgrammingOutlineModularity and EncapsulationIs AOP Modular?Example: Assurance AspectSlide 6Slide 7Slide 8Slide 9Example: Broken Assurance AspectSlide 11Slide 12AnalysisFix #1: external adviceFix #2: semantic pointcutOpen ModulesSlide 17Slide 18Slide 19Slide 20Slide 21Open Module Properties: EquivalenceOpen Module Properties: AbstractionComparison to Aspect-Aware InterfacesTool and Language ImplicationsDiscussionEnd of Presentation/Extra SlidesTinyAspect ExampleTinyAspect: SyntaxEvaluationSlide 31TinyAspect: Values and ContextsTinyAspect: Reduction RulesTinyAspect: Expression TypingTinyAspect: Declaration TypingTinyAspect: PropertiesOpen Modules: SyntaxOpen Modules: ExampleOpen Modules: SemanticsSlide 40Reynolds’ Abstraction PropertyObservational EquivalenceFormal Abstraction TheoremA Formal Model of Modularityin Aspect-Oriented ProgrammingJonathan Aldrich15-819: Objects and AspectsCarnegie Mellon UniversityOutlineAOP Modularity ChallengesOpen ModulesA Bit of FormalityComparison to Aspect-Aware InterfacesLessons Learned and DiscussionModularity and EncapsulationParnas’ advice:Modularize a system to hide information that may changeEncapsulationA mechanism for enforcing information hidingJava classes & packages, ML modules…Aspect-oriented ProgrammingMore flexible ways of modularizing a systemIs AOP Modular?Back to Parnas: Does AOP hide information that is likely to change?Yes, within the aspectAspect code can be evolved separatelyNo, not within the base codeMinor changes to base code break the aspectExample: Assurance Aspectclass Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy; ...}Example: Assurance Aspectclass Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy; ...}class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy; ...}Example: Assurance Aspectclass Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy; ...}class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy; ...}aspect AssureShapeInvariants { }Example: Assurance Aspectclass Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy; ...}class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy; ...}aspect AssureShapeInvariants { pointcut moves() = call(Shape+.moveBy(..)); }Example: Assurance Aspectclass Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy; ...}class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy; ...}aspect AssureShapeInvariants { pointcut moves() = call(Shape+.moveBy(..)); after(): moves() { scene.checkInvariants(); }}Example: Broken Assurance Aspectclass Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy; ...}class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy; ...}aspect AssureShapeInvariants { pointcut moves() = call(Shape+.moveBy(..)); after(): moves() { scene.checkInvariants(); }}Change representation to use PointExample: Broken Assurance Aspectclass Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy; ...}class Rectangle extends Shape { void moveBy(int dx, int dy) { p1.moveBy(dx, dy); p2.moveBy(dx, dy); ...}aspect AssureShapeInvariants { pointcut moves() = call(Shape+.moveBy(..)); after(): moves() { scene.checkInvariants(); }}Change representation to use PointExample: Broken Assurance Aspectclass Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy; ...}class Rectangle extends Shape { void moveBy(int dx, int dy) { p1.moveBy(dx, dy); p2.moveBy(dx, dy); ...}aspect AssureShapeInvariants { pointcut moves() = call(Shape+.moveBy(..)); after(): moves() { scene.checkInvariants(); }}Change representation to use PointNow the scene invariants are checked in the middle of a Rectangle move—when they might be broken!AnalysisAspects can violate information hidingAssurance aspect depends on Shape internalsSimilar to OO Fragile Base Class ProblemObserving impl. dependant calling patternsCan fix each individual problemBetter: use modules to forestall issueFix #1: external adviceclass Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy; ...}class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy; ...}aspect AssureShapeInvariants { pointcut moves(): call(Shape+.moveBy(..)) && !within(shape.*); after(): moves() { scene.checkInvariants(); }}Only specifies calls that are external to the shape packageFix #2: semantic pointcutclass Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy; ...}class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy; ...}class Shape { public pointcut moves(): call(Shape+.moveBy(..));}aspect AssureShapeInvariants { after(): Shape.moves() { scene.checkInvariants(); }}Move pointcut to the shape packageNow the shape maintainer is responsible for preserving its semantics when shapes evolveOpen Modulesvoid moveBy(int, int);void animate(Motion);Open ModuleOrdinary functional interfaceOpen Modulesvoid moveBy(int, int);void animate(Motion);pointcut moves;Open ModuleOrdinary functional interfaceSemantic Pointcut• Denotes some internal event• Promise to maintain event semantics as code evolves[Gudmunson & Kiczales]Open Modulesvoid moveBy(int, int);void animate(Motion);pointcut moves;Open ModuleClients can call interface functionsOpen Modulesvoid moveBy(int, int);void animate(Motion);pointcut moves;Open ModuleClients can call interface functionsClients can advise external calls to interface functionsOpen Modulesvoid moveBy(int, int);void animate(Motion);pointcut moves;Open ModuleClients can call interface functionsClients can advise external calls to interface functionsClients can advise pointcuts in interfaceOpen Modulesvoid moveBy(int, int);void animate(Motion);pointcut moves;Open ModuleClients can call interface functionsClients can advise external calls to interface functionsClients can advise pointcuts in interfaceClients cannot advise any internal calls (not even to exported


View Full Document

CMU CS 15819 - A Formal Model of Modularity in Aspect-Oriented Programming

Download A Formal Model of Modularity in Aspect-Oriented Programming
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view A Formal Model of Modularity in Aspect-Oriented Programming and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view A Formal Model of Modularity in Aspect-Oriented Programming 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?