Title: ADAPTIVE PROGRAMMING
1ADAPTIVE PROGRAMMING
- Sezen ERDEM
- December 2005
2Outline
- What is Adaptive Programming?
- Law of Demeter
- Structure-Shy Behavior (Traversal Strategy)
- Propagation Patterns
- Example
- Development Tools
- Conclusion
3What is Adaptive Programming?
- Changes its behavior according to its environment
- Encapsulates class hierarchies using traversal
strategies and visitors - An extension of OOP using graph theory and formal
languages to further abstract collaborating
classes and generate a family of programs from a
common architectural graph.
4What is Adaptive Programming?
- Aspects or components use graphs which are
described by traversal strategies. - A traversal strategy defines traversals of graphs
without referring to the details. - Adaptive programming is aspect-oriented
programming with traversal strategies.
5What is Adaptive Programming?
- Adapts automatically to changing context
- Class structures are described partially
- Behavior is not implemented exhaustively
- Methods are implemented when they are needed
6History
- 1982 Hades (Hardware DEScription language by
Niklaus Wirth at ETH Zurich) - 1982-1985 Zeus (brother of Hades, a silicon
compilation language developed at Princeton
University/MIT) - 1985-Present Demeter (sister of Zeus, used to
implement Zeus, started at GTE Labs)
7History (Contd)
- 1990 First traversal specifications
- 1995 Separation of Concerns by Huersch and
Lopes started untangling movement. - Collaboration with Xerox PARC began
- 1996 Gregor Kiczales and his group further
develop Aspect Oriented Programming
8Law of Demeter
- originally formulated as a style rule for
designing object-oriented systems - Each unit should have only limited knowledge
about other units only units "closely" related
to the current unit. - each unit should only talk to its friends
- DO NOT TALK TO STRANGERS !!!
9Law of Demeter
- More specific case of Low Coupling Principle
- The motivation for the Law of Demeter is to
control information overload - When writing a method, one should not hardwire
the details of the class structure into that
method
10Structure-Shy Behavior (Traversal Strategy)
- Programming is shy if it hides details of other
concerns it cuts across - Gathers the code describing the traversal in one
place with minimal dependency on the class
structure - Compliant with Law of Demeter
11Structure-Shy Behavior(Traversal Strategy)
- Allows one to specify strategies that ignore
certain parts of the concrete structure - Lowers the coupling of code from the concrete
structure - Lessens the dependency of code changes when
structure changes - Idea is to capture the essential structure and
ignore the rest.
12Structure-Shy Behavior
- An implementation of a concern C1 is C2-shy if
- The C1 implementation relies only on minimal
information of C2 implementations. - The C1 implementation can adapt to small changes
in C2 implementations. - The C1 implementation is loosely coupled with C2
implementations. - The C1 implementation can work with C2 , C2 ,
C2 which are close or similar to C2
implementations.
13Structure-Shy Behaviour
better program
ordinary program
structure-shy functionality
Components
structure
Aspect 1
synchronization
Aspect 2
14Propagation Patterns
- Adaptive program is specified using a collection
of propagation patterns. - Propagation patterns specify a set of related
constraints in the adaptive program - Given a customizing Class Dictionary Graph, a
propagation pattern produces an OO program
denoted by the adaptive program it specifies
15Class Dictionary Graph
16Class Dictionary Graph
- Vertices
- Construction Vertex Abstraction of a classs
definition - Alternation Vertex Define union classes
- Repetition Vertex Represents lists
- Edges
- Alternation Edges Represents alternative
relationship - Construction Edges Represents parts
17Class Dictionary Graph
18Propagation Graph
- Customize a propagation pattern with class
dictionary graph, its traversal specifications
induce a set of paths - Propagation Graph
- Sum up the total salary of officers
19Propagation Graph Code Generation
- For each vertex in the propagation graph
- A method is created with the signature given by
the operation specification in the propagation
pattern. - The body for this method contains as many calls
as the given vertex has outgoing construction
edges in the propagation graph. - Each call is made to the method with the same
signature attached to the vertex target of the
corresponding construction edge. - Finally, each wrapper code fragment in the
propagation - pattern is prefixed or appended to the generated
code for the vertex or edge it specifies.
20Example
UML CLASS DIAGRAM
busStops
BusRoute
BusStopList
buses
0..
BusStop
BusList
waiting
0..
passengers
Bus
PersonList
Person
0..
21Collaborating Classes
find all people waiting at any bus stop on a bus
route
busStops
BusRoute
BusStopList
buses
0..
BusStop
BusList
waiting
0..
passengers
Bus
PersonList
Person
0..
22Traversal Strategy
from BusRoute through BusStop to Person
busStops
BusRoute
BusStopList
buses
one method for each red class
0..
BusStop
BusList
waiting
0..
passengers
Bus
PersonList
Person
0..
23Traversal Strategy
from BusRoute bypassing Bus to Person
busStops
BusRoute
BusStopList
buses
0..
BusStop
BusList
waiting
0..
passengers
Bus
PersonList
Person
0..
24Robustness of Strategy
from BusRoute through BusStop to Person
villages
BusRoute
BusStopList
busses
VillageList
busStops
0..
0..
BusStop
BusList
Village
waiting
0..
passengers
Bus
PersonList
Person
0..
25DJ Implementation
class BusRoute int countPersons(TraversalGraph
WP) Integer result
(Integer)WP.traverse(this, new Visitor() int
r public void before(Person host) r
public void start() r 0
public Object getReturnValue()
return new Integer ( r) )
return result.intValue()
26DJ Implementation
ClassGraph classGraph new ClassGraph() Travers
alGraph WPTraversal new TraversalGraph
(from BusRoute via BusStop to Person,
classGraph) int r aBusRoute.countPersons(WPTr
aversal)
27Taxi driver analogy
- Streets and intersections correspond to class
graph - Traversal strategy determines how the taxi will
navigate through the streets - You can take pictures before and after
intersections - You can veto sub traversals
28Development Tools
- DJ and AP Library
- Demeter/C
- DemeterJ
- Demeter/StKlos
- Dem/Perl5
- Dem/C
- Dem/CLOS
- Demeter/Object Pascal
29Advantages of AP
- Focus on the essence of a problem to be solved
and leads to simpler and shorter than
conventional object-oriented programs. - Promote reuse.
- Robust to changes
- Design matches program
- More understandable code
- Improved productivity
30Conclusion
- We covered
- What Adaptive Programming is
- Law of Demeter
- Traversal Strategies
- Propagation Patterns
- Development Tools
- Advantages of Adaptive Programming
31References
- http//www.ccs.neu.edu/research/demeter
- Adaptive Object Oriented Software
- Karl Liebher
- Adaptive Programming
- Mohammed G. Gauda Ted Herman
32QUESTIONS