Title: Adaptive ObjectOriented Software Development
1Adaptive Object-OrientedSoftware Development
http//www.ccs.neu.edu/home/lieber/com3360/w03/w03
.html
2Introduction
- Software engineering, modeling, design, software
architecture - Programming languages
- Hands-on, practical, useful
3Summary of Course
- How to design and implement flexible
object-oriented software using the principles of
adaptiveness and separation of concerns in
combination with UML and Java. Learning
principles behind AspectJ and XML. - How to design and implement flexible 100 pure
Java software minimizing scattering and tangling
of crosscutting behavioral concerns.
4Who is in Attendance?
- Software developers who have experience with
object-oriented programming. - Should know concepts of OOP, like classes,
methods, and late binding.
5Academic Integrity
- Tension
- Learning from your peers is valuable
- for technical help this program does not run
properly and I have tried for two hours to figure
out why can I explain my program to you? - for discussing ways to think about the concepts
- for project work if you work in a team of two
- for getting a concept explained
- for sharing frustrations
- Independent scholarship
6Academic Integrity
- Independent scholarship
- required for writing the homework solutions
- required for exams
7Important Rules
- Learn when to go inside and solve the problems
yourself. - Learn when it is appropriate to use help from a
peer. - Follow rules of handout.
8Featured in MIT Technology Magazine 2001 as a Top
Ten Technology
Agenda
Aspect-Oriented Progr. Adaptive Programming
DemeterJ Java and DJ Java environment UML XML
strategy graphs class graphs object graphs state
graphs
principles heuristics patterns idioms theorems alg
orithms
requirements domain analysis design implementation
use cases interfaces traversals visitors packages
Demeter Method iterative development spiral
model Extreme Programming
9Aspect-Oriented Software Development (AOSD)
- Observation many concerns of the
designer/programmer are scattered across many
classes or methods and tangled with code of other
concerns. - A concern is called crosscutting, if its ad-hoc
implementation is scattered. - AOSD is about cleanly modularizing crosscutting
concerns. A modularized crosscutting concern is
called an aspect. - Reduces scattering and tangling.
10Agenda
- UML class diagrams. Perspective analysis,
design, implementation - Class graphs as special cases of UML class
diagrams - Textual representation of class graphs
- Default implementation of UML class diagrams as
class graphs
11Agenda
- UML interaction diagrams
- sequence diagrams
- collaboration diagrams
- improving interaction diagrams to make them
specification languages - XML data type definitions and documents
12Agenda
- Class graphs in textual form (construction,
alternation) - object graphs (graphical and textual form)
- object graphs defined by class graphs
- add repetition classes and optional parts
- translating class graphs to Java
13Agenda
- annotating class graph with syntax class
dictionary - printing objects and language defined by class
dictionary - grammars, parsing, ambiguous grammars,
undecidable problem - LL(1) grammars, robustness of sentences
- etc.
14Overview
- good separation of concerns is the goal
- concerns should be cleanly localized
- programs should look like designs
15Adaptive Programming
- Programs adapt to interesting context changes
- Structure-shy behavior
- Succinct representation of traversals
- Programming in terms of graph constraints
16Cross-cutting of concerns
better program
ordinary program
structure-shy functionality
Components
structure
Aspect 1
synchronization
Aspect 2
17Modularization of crosscutting concerns
Instead of writing this
18Aspect-Oriented Programming
components and aspect descriptions
High-level view, implementation may be different
Source Code (tangled code)
weaver (compile- time)
19Examples of Aspects
- Collaborations, use cases
- Synchronization of methods across classes
- Remote invocation (using Java RMI)
- Quality of Service (QoS)
- Failure handling
- External use (e.g., being a Java bean)
- Replication, Migration
20Connections
- explain adaptive programming in terms of
patterns - Aspect-Oriented Programming (AOP) is a
generalization of Adaptive Programming (AP) - correspondence
- adaptive program object-oriented program
sentence object graph
21Vocabulary
- Graph, nodes, edges, labels
- Class graph, construction, alternation
- Object graph, satisfying class graph
- UML class diagram
- Grammar, printing, parsing
22Vocabulary
- Traversals, visitors
- Strategy graphs, path set
23Overview this lecture
- Basic UML class diagrams
- Traversals/Collaborating classes
- Traversal strategy graphs
- Adaptive programming
- Tools for adaptive programming
- DemeterJ and AP/Studio
241 Basic UML class diagrams
- Graph with nodes and directed edges and labels
for nodes and edges - Nodes classes, edges relationships
- labels class kind, edge kind, cardinality
25UML Class Diagram
busStops
BusRoute
BusStopList
buses
0..
BusStop
BusList
waiting
0..
passengers
Bus
PersonList
Person
0..
262 Traversals / Collaborating classes
- To process objects we need to traverse them
- Traversal can be specified by a group of
collaborating classes
27Collaborating Classes
use connectivity in class graph to define them
succinctly using strategy graphs
from Customer to Agent
from Company to Employee
28What's the problem? TANGLING
OOAD
Collab-1
C1
C4
C2
C3
C5
Collab-4
Collab-2
Collab-3
C1
C4
C2
C3
Implementation
C5
29Collaborating 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..
303 Traversal Strategy Graphs
- Want to define traversals succinctly
- Use strategy graphs to express abstraction of
class diagram - Express traversal intent useful for
documentation of object-oriented programs
31Traversal Strategy
find all persons waiting at any bus stop on a bus
route
first try from BusRoute to Person
busStops
BusRoute
BusStopList
buses
0..
BusStop
BusList
waiting
0..
passengers
Bus
PersonList
Person
0..
32Traversal Strategy
find all persons waiting at any bus stop on a bus
route
from BusRoute through BusStop to Person
busStops
BusRoute
BusStopList
buses
0..
BusStop
BusList
waiting
0..
passengers
Bus
PersonList
Person
0..
33Traversal Strategy
find all persons waiting at any bus stop on a bus
route
Altern. from BusRoute bypassing Bus to Person
busStops
BusRoute
BusStopList
buses
0..
BusStop
BusList
waiting
0..
passengers
Bus
PersonList
Person
0..
34Robustness of Strategy
find all persons waiting at any bus stop on a bus
route
from BusRoute through BusStop to Person
villages
BusRoute
BusStopList
busses
VillageList
busStops
0..
0..
BusStop
BusList
Village
waiting
0..
passengers
Bus
PersonList
Person
0..
35Filter out noise in class diagram
- only three out of seven classes
- are mentioned in traversal
- strategy!
from BusRoute through BusStop to Person
replaces traversal methods for the classes
BusRoute VillageList Village BusStopList
BusStop PersonList Person
36Why Traversal Strategies?
- Law of Demeter a method should talk only to its
- friends
- arguments and part objects (computed or
stored) - and newly created objects
- Dilemma
- Small method problem of OO (if followed) or
- Unmaintainable code (if not followed)
- Traversal strategies are the solution to this
dilemma
374 Adaptive Programming
- How can we use strategies to program?
- Need to do useful work besides traversing
visitors - Incremental behavior composition using visitors
38Styles of Adaptive Programming
- Traditional parameterize by class graph
strategy is part of adaptive program - Traditional optimized parameterize by class
graph and strategy graph reuse pair of class
graph and strategy graph.
39Writing Adaptive Programs with Strategies
(DJpure Java)
String WPSfrom BusRoute through BusStop to
Person
class BusRoute int countPersons(ClassGraph
cg) String WPSfrom BusRoute through
BusStop to Person Integer result
(Integer) cg.traverse(this, WPS, 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()
40Writing Adaptive Programs with Strategies
(DJpure Java)
// Prepare the class graph ClassGraph classGraph
new ClassGraph() int r aBusRoute.countPerso
ns(classGraph)
41Goal of DJ
- Focus on crosscutting traversal-related concerns
involve a group of collaborating objects which
are manipulated to implement a behavior. - Provide a Java library to cleanly encapsulate
crosscutting traversal-related concerns whose ad
hoc implementation would be scattered across many
classes.
42Solves Open Problem in AOPfor Behavioral Aspects
in Java
- The ClassGraph-Aspect-Freezing problem
- When we have n behavioral aspects and the class
graph changes, we potentially need to update all
n aspects. - DJ allows us to loosely couple behavioral aspects
to the class graph. - And this is all done in Java using REFLECTION.
43Writing Adaptive Programs with Strategies
(DJpure Java)
String WPStrategyfrom BusRoute through BusStop
to Person
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()
44Writing Adaptive Programs with Strategies
(DJpure Java)
String WPStrategyfrom BusRoute through BusStop
to Person
// Prepare the traversal for the current class
graph ClassGraph classGraph new
ClassGraph() TraversalGraph WPTraversal new
TraversalGraph (WPStrategy, classGraph) int
r aBusRoute.countPersons(WPTraversal)
45Writing Adaptive Programs with Strategies
(DJpure Java)
class Utility static int
countPersons(ObjectGraphSlice countSlice)
Integer result (Integer)
countSlice.traverse(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()
46Writing Adaptive Programs with Strategies
(DJpure Java)
String WPStrategyfrom BusRoute through BusStop
to Person
// Prepare the slice for the current class
graph ClassGraph classGraph new
ClassGraph() ObjectGraph objectGraph new
ObjectGraph(aBusRoute) ObjectGraphSlice
whatToCount new ObjectGraphSlice(objectGraph,
WPStrategy) int r Utility.countPersons(whatT
oCount)
47Writing Adaptive Programs with Strategies
(DemeterJ)
strategy from BusRoute through BusStop to Person
BusRoute int printCountWaitingPersons() //
traversal/visitor weaving through BusStop
to Person (PrintPersonVisitor)
PrintPersonVisitor before Person
PersonVisitor init r 0
THIS IS NOT JAVA
Extension of Java keywords init through
bypassing to before after etc.
48Writing Adaptive Programs with Strategies
(DemeterJ)
strategy from BusRoute through BusStop to Person
BusRoute traversal waitingPersons(PersonVis
itor) through BusStop to Person //
from is implicit int printCountWaitingPersons(
) // traversal/visitor weaving
waitingPersons(PrintPersonVisitor) PrintPersonVi
sitor before Person
PersonVisitor init r 0
THIS IS NOT JAVA
Extension of Java keywords traversal
init through bypassing to before after etc.
49Taxi 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
50Programming in Large Families
Two adaptive programs
A1
Class Graphs
A2
A1 family
Object-Oriented Programs
A2 family
51Adaptive Programming
Strategy
Bold names refer to DJ classes.
is use-case based abstraction of
ClassGraph
defines family of
ObjectGraph
52Adaptive Programming
Strategy
defines traversals of
ObjectGraph
53Adaptive Programming
Strategy
guides and informs
Visitor
54Strategies
BusRoute BusStop Person
- Nodes positive information Mark corner stones
in class graph Overall topology - of collaborating classes. 3 nodes
- from BusRoute
- through BusStop
- to Person
55Strategies
bypassing edges incident with Bus
BusRoute
Person
Edges negative information Delete edges from
class graph.
from BusRoute bypassing Bus to Person
565 Tools for Adaptive Programming
- free and commercial tools available
57Free Tools on WWW
- DJ and AP Library
- Demeter/C
- DemeterJ
- Demeter/StKlos
- Dem/Perl5
- Dem/C
- Dem/CLOS
- Demeter/Object Pascal
last four developed outside our group
58Benefits of Adaptive Programming
- robustness to changes
- shorter programs
- design matches program
- more understandable code
- partially automated evolution
- keep all benefits of OO technology
- improved productivity
Applicable to design and documentation of your
current systems.
59DemeterJ
www.ccs.neu.edu/research/demeter
- class diagrams
- functionality
- strategies
- visitors
- etc.
Executable Java code for your favorite commercial
Java Software Development Environment
weaver
60DemeterJ in DemeterJ
structure (.cd) class diagrams
focus of this lecture
compiler/ weaver
structure-shy behavior (.beh) strategies
and visitors
structure-shy communication (.ridl) distribution
structure-shy object description (.input, at
runtime)
synchronization (.cool) multi threading
61Cross-cutting in DemeterJ
generated Java program
DemeterJ program
structure-shy functionality
structure
replicated!
synchronization
62AP Studio
- visual development of traversal strategies
relative - to class diagram
- visual feedback about collaborating classes
- visual development of annotated UML class diagrams
has not been used much
63Strengths of DemeterJ
- Theory
- Novel algorithms for strategies
- Formal semantics
- Correctness theorems
- Practice
- Extensive feedback (8 years)
- Reflective implementation
64Meeting the Needs
- DemeterJ
- Easier evolution of class diagrams (with strategy
diagrams) - Easier evolution of behavior (with visitors)
- Easier evolution of objects (with sentences)
- Better separation of crosscutting
traversal-related concerns
65Real Life
- Used in several commercial projects
- Implemented by several independent developers
- Used in several courses, both academic and
commercial
66Summary
- What has been learned Simple UML class diagrams,
strategies and adaptive programs - How can you apply
- DemeterJ takes adaptive programs as input
- Document and implement object-oriented programs
with strategies using DJ in Java - Design in terms of traversals and visitors
67Where to get more information
- Adaptive Programming book
- DJ home page
- DemeterJ home page
- Course home page
- www.ccs.neu.edu/research/demeter/
68Feedback
- Request feedback of training session