Download presentation
Presentation is loading. Please wait.
Published byAshley Fox Modified over 6 years ago
1
David Evans http://www.cs.virginia.edu/~evans
Lecture 21: Crosscutting Aspect-Oriented Programming Background just got here last week finished degree at MIT week before Philosophy of advising students don’t come to grad school to implement someone else’s idea can get paid more to do that in industry learn to be a researcher important part of that is deciding what problems and ideas are worth spending time on grad students should have their own project looking for students who can come up with their own ideas for research will take good students interested in things I’m interested in – systems, programming languages & compilers, security rest of talk – give you a flavor of the kinds of things I am interested in meant to give you ideas (hopefully even inspiration!) but not meant to suggest what you should work on CS655: Programming Languages University of Virginia Computer Science David Evans
2
Adaptive Programming: Demeter
Instance of AOP [Lieberherr92] Separate the program text and the class structure Program is independent of class graph Accomplish tasks by traversals Specification for what parts of received object should be traversed Code fragments for what to execute when specific object types are encountered 15 January 2019 University of Virginia CS 655
3
University of Virginia CS 655
Law of Demeter Law of Demeter: a method should talk only to its friends: arguments and part objects (computed or stored) newly created objects Dilemma: Small method problem of OO (if followed) Unmaintainable code (if not followed) Traversal strategies are the solution to this dilemma Demeter = Greek Goddess of Agriculture (grow software from small blocks) 15 January 2019 University of Virginia CS 655
4
AP Example: UML Class Diagram
Slide adapted from Karl Lieberherr talk AP Example: UML Class Diagram busStops BusRoute BusStopList buses 0..* BusStop BusList waiting 0..* passengers Example for developing strategies and writing adaptive programs Bus PersonList Person 0..* 1/15/2019 AOP/Demeter
5
Collaborating Classes
Slide adapted from Karl Lieberherr talk Collaborating Classes Find all persons waiting at any bus stop on a bus route busStops BusRoute BusStopList OO solution: one method for each red class buses 0..* BusStop BusList waiting 0..* passengers Bus PersonList Person 0..* 1/15/2019 AOP/Demeter
6
Java Solution (excerpt)
class BusRoute { BusStopList busstops; void printWaitingPassengers () { busstops->printWaitingPassengers (); } } class BusStopList { BusStop stops[]; for (int i = 0; i < stops.length; i++) stops[i].printWaitingPassengers (); 15 January 2019 University of Virginia CS 655
7
University of Virginia CS 655
Java Solution (cont.) class BusStop { PersonList waiting; void printWaitingPassengers () { waiting.print (); } } class PersonList { Person people[]; void print () { for (int i = 0; i < people.length; i++) people[i].print (); } class Person { String name; void print () { System.stdout.println (name); } } 15 January 2019 University of Virginia CS 655
8
University of Virginia CS 655
Demeter Approach Devise a traversal strategy Specify code for different types of objects reached on a traversal Example: code prints name if object is a Person Independent of class graph 15 January 2019 University of Virginia CS 655
9
Slide adapted from Karl Lieberherr talk
Traversal Strategy First try: from BusRoute to Person busStops BusRoute BusRoute BusStopList BusStopList buses 0..* BusStop BusStop BusList BusList waiting 0..* passengers Bus Bus PersonList PersonList Person Person 0..* 1/15/2019 AOP/Demeter
10
Slide adapted from Karl Lieberherr talk
Traversal Strategy from BusRoute through BusStop to Person busStops BusRoute BusStopList buses 0..* BusStop BusList waiting 0..* passengers Bus PersonList Person 0..* 1/15/2019 AOP/Demeter
11
Robustness of Strategy
Slide adapted from Karl Lieberherr talk Robustness of Strategy from BusRoute bypassing Bus to Person villages BusRoute BusStopList buses VillageList busStops 0..* 0..* BusStop BusList Village waiting 0..* passengers Bus PersonList Person 0..* 1/15/2019 AOP/Demeter
12
Filter out noise in class diagram
Slide adapted from Karl Lieberherr talk Filter out noise in class diagram only three out of seven classes are mentioned in traversal strategy! from BusRoute through BusStop to Person explain why strategy better replaces traversal methods for the classes BusRoute VillageList Village BusStopList BusStop PersonList Person 1/15/2019 AOP/Demeter
13
University of Virginia CS 655
Summary Aspect-Oriented Programming and Adaptive Programming provide programmers with new expressive options Active research area (Separation of Concerns Workshops at OOPSLA, ICSE, ECOOP, etc.) Many directions to explore 15 January 2019 University of Virginia CS 655
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.