Adaptive Object-Oriented Software Development The Demeter Method 5/13/2016
Download
Report
Transcript Adaptive Object-Oriented Software Development The Demeter Method 5/13/2016
Adaptive Object-Oriented
Software Development
The Demeter Method
5/13/2016
AOOP / Demeter
1
Introduction
• Software engineering
• Programming languages
• Hands-on, practical, useful
5/13/2016
AOOP / Demeter
2
Summary of Course
• How to design and implement flexible
object-oriented software using the
principles of adaptiveness.
• How to design and implement flexible
100% pure Java software
5/13/2016
AOOP / Demeter
3
Who is in Attendance?
• Software developers who have some
experience with object-oriented
programming.
• Should know concepts of OOP, like classes,
methods, and late binding.
5/13/2016
AOOP / Demeter
4
Agenda for Adaptive Object-Oriented Software/Demeter
Demeter/Java
Java
Java environment
UML
XML
requirements
domain analysis
design
implementation
5/13/2016
Adaptive Programming
Aspect-Oriented Progr.
principles
heuristics
patterns
idioms
theorems
algorithms
Demeter Method
iterative development
spiral model
AOOP / Demeter
strategy graphs
class graphs
object graphs
state graphs
use cases
interfaces
traversals
visitors
packages
5
Agenda
• 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
5/13/2016
AOOP / Demeter
6
Agenda
• UML interaction diagrams
– sequence diagrams
– collaboration diagrams
– improving interaction diagrams to make them
specification languages
5/13/2016
AOOP / Demeter
7
Agenda
• 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
5/13/2016
AOOP / Demeter
8
Agenda
• 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.
5/13/2016
AOOP / Demeter
9
Overview
• good separation of concerns is the goal
• concerns should be cleanly localized
• programs should look like designs
5/13/2016
AOOP / Demeter
10
Adaptive Programming
• Programs adapt to interesting context
changes
• Structure-shy behavior
• Succinct representation of traversals
• Programming in terms of graph constraints
5/13/2016
AOOP / Demeter
11
Cross-cutting of components and
aspects
better program
ordinary program
structure-shy
functionality
Components
Aspect 1
structure
Aspect 2
synchronization
5/13/2016
AOOP / Demeter
12
Aspect-Oriented Programming
components and aspect descriptions
High-level view,
implementation may
be different
Source Code
(tangled code)
weaver
(compiletime)
5/13/2016
AOOP / Demeter
13
Examples of Aspects
•
•
•
•
•
•
•
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
etc.
5/13/2016
AOOP / Demeter
14
Connections
• 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
5/13/2016
AOOP / Demeter
15
Vocabulary
•
•
•
•
•
Graph, nodes, edges, labels
Class graph, construction, alternation
Object graph, satisfying class graph
UML class diagram
Grammar, printing, parsing
5/13/2016
AOOP / Demeter
16
Vocabulary
• Traversals, visitors
• Strategy graphs, path set
5/13/2016
AOOP / Demeter
17
Overview this lecture
•
•
•
•
•
•
Basic UML class diagrams
Traversals/Collaborating classes
Traversal strategy graphs
Adaptive programming
Tools for adaptive programming
Demeter/Java and AP/Studio
5/13/2016
AOOP / Demeter
18
1: 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
5/13/2016
AOOP / Demeter
19
UML Class Diagram
busStops
BusRoute
BusStopList
buses
0..*
BusStop
BusList
0..*
waiting
passengers
Bus
PersonList
Person
5/13/2016
AOOP / Demeter
0..*
20
2: Traversals / Collaborating
classes
• To process objects we need to traverse them
• Traversal can be specified by a group of
collaborating classes
5/13/2016
AOOP / Demeter
21
Collaborating Classes
use connectivity in class graph to define them succinctly
using strategy graphs
from Company to Employee
5/13/2016
AOOP / Demeter
from Customer to Agent
22
OOAD
self-service
customer service
center
Z
teller service
Collab-1
C1
C2
C4
C3
C5
Collab-2
C1
C2
Collab-3
C4
C3
Implementation
C5
5/13/2016
Collab-4
AOOP / Demeter
23
Collaborating Classes
find all persons waiting at any bus stop on a bus route
busStops
BusRoute
buses
BusList
0..*
BusStopList
OO solution:
one method
for each red
class
BusStop
waiting
passengers
Bus
PersonList
Person
5/13/2016
0..*
AOOP / Demeter
0..*
24
3: Traversal Strategy Graphs
• Want to define traversals succinctly
• Use graph to express abstraction of class
diagram
• Express traversal intent: useful for
documentation of object-oriented programs
5/13/2016
AOOP / Demeter
25
find all persons waiting at any bus stop on a bus route
Traversal Strategy
first try: from BusRoute to Person
busStops
BusRoute
BusStopList
buses
0..*
BusStop
BusList
0..*
waiting
passengers
Bus
PersonList
Person
5/13/2016
AOOP / Demeter
0..*
26
find all persons waiting at any bus stop on a bus route
Traversal Strategy
from BusRoute through BusStop to Person
busStops
BusRoute
BusStopList
buses
0..*
BusStop
BusList
0..*
waiting
passengers
Bus
PersonList
Person
5/13/2016
AOOP / Demeter
0..*
27
find all persons waiting at any bus stop on a bus route
Traversal Strategy
Altern.: from BusRoute bypassing Bus to Person
busStops
BusRoute
BusStopList
buses
0..*
BusStop
BusList
0..*
waiting
passengers
Bus
PersonList
Person
5/13/2016
AOOP / Demeter
0..*
28
find all persons waiting at any bus stop on a bus route
Robustness of Strategy
from BusRoute bypassing Bus to Person
BusRoute
buses
BusList
0..*
villages
VillageList
0..*
Village
busStops
0..*
BusStop
waiting
passengers
Bus
PersonList
Person
5/13/2016
BusStopList
AOOP / Demeter
0..*
29
Filter 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
5/13/2016
AOOP / Demeter
30
find all persons waiting at any bus stop on a bus route
Even better: interface class graph
from BusRoute through BusStop to Person
busStops
BusStop
BusRoute
0..*
waiting
buses
0..*
Bus
passengers
0..*
Person
0..*
5/13/2016
AOOP / Demeter
31
Map interface class graph to
application class graph
from BusRoute through BusStop to Person
BusRoute
buses
BusList
0..*
villages
VillageList
0..*
Village
5/13/2016
busStops
0..*
BusStop
waiting
passengers
Bus
edge -> path
BusStopList
PersonList
Person
AOOP / Demeter
0..*
32
Map interface class graph to
application class graph
from BusRoute through BusStop to Person
BusRoute
villages
BusStopList
VillageList
0..*
busStops
BusStop
Village
busStops
BusRoute
edge -> path
5/13/2016
0..*
BusStop
0..*
AOOP / Demeter
33
Benefits of interface class graph
• Shields program from details of application
class graph
• Makes program more robust and simpler
5/13/2016
AOOP / Demeter
34
Why 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
5/13/2016
AOOP / Demeter
35
4: Adaptive Programming
• How can we use strategies to program?
• Need to do useful work besides traversing:
visitors
• Incremental behavior composition using
visitors
5/13/2016
AOOP / Demeter
36
Writing Adaptive Programs with
Strategies
strategy: from BusRoute through BusStop to Person
BusRoute {
traversal waitingPersons(PersonVisitor) {
through BusStop to Person; } // from is implicit
int printWaitingPersons() // traversal/visitor weaving instr.
= waitingPersons(PrintPersonVisitor);
PrintPersonVisitor {
before Person (@ … @) … }
PersonVisitor {init (@ r = 0; @) … }
Extension of Java: keywords: traversal init
through bypassing to before after etc.
5/13/2016
AOOP / Demeter
37
Taxi 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
5/13/2016
AOOP / Demeter
38
Programming in Large Families
Two adaptive programs
A1
Class Graphs
A2
A1 family
Object-Oriented Programs
A2 family
5/13/2016
AOOP / Demeter
39
Adaptive Programming
Strategy Diagrams
are use-case based
abstractions of
Class Diagrams
define family of
Object Diagrams
5/13/2016
AOOP / Demeter
40
Adaptive Programming
Strategy Diagrams
define traversals
of
Object Diagrams
5/13/2016
AOOP / Demeter
41
Adaptive Programming
Strategy Diagrams
guide and
inform
Visitors
5/13/2016
AOOP / Demeter
42
Strategy Diagrams
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
5/13/2016
AOOP / Demeter
43
Strategy Diagrams
bypassing edges incident with Bus
BusRoute
Person
Edges: negative information:
Delete edges from class diagram.
from BusRoute bypassing Bus to Person
5/13/2016
AOOP / Demeter
44
5: Tools for Adaptive
Programming
• free and commercial tools available
5/13/2016
AOOP / Demeter
45
Free Tools on WWW
•
•
•
•
•
•
•
Demeter/C++
Demeter/Java
Demeter/StKlos
Dem/Perl5
last four developed outside our group
Dem/C++
Dem/CLOS
Demeter/Object Pascal
5/13/2016
AOOP / Demeter
46
Commercial Tools available on
WWW
StructureBuilder from Tendril Software Inc.
next release will have support for traversals
www.tendril.com
5/13/2016
AOOP / Demeter
47
Benefits of Demeter
• 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.
5/13/2016
AOOP / Demeter
48
Demeter/Java
•class diagrams
•functionality
•strategies
•visitors
•etc.
www.ccs.neu.edu/research/demeter
Executable
Java code for your
favorite
commercial Java
Software
Development
Environment
weaver
5/13/2016
AOOP / Demeter
49
Demeter/Java in Demeter/Java
structure (*.cd)
class diagrams
structure-shy
communication
(*.ridl)
distribution
compiler/
weaver
synchronization (*.cool)
multi threading
5/13/2016
AOOP / Demeter
focus of this lecture
structure-shy
behavior
(*.beh)
strategies and
visitors
structure-shy
object description
(*.input, at runtime)
50
Cross-cutting in Demeter/Java
generated
Java program
Demeter/Java program
structure-shy
functionality
structure
replicated!
synchronization
5/13/2016
AOOP / Demeter
51
AP Studio
•visual development of traversal strategies relative
to class diagram
•visual feedback about collaborating classes
•visual development of annotated UML class diagrams
5/13/2016
AOOP / Demeter
52
Strengths of Demeter/Java
•Theory
•Novel algorithms for strategies
•Formal semantics
•correctness theorems
•Practice
•Extensive feedback (8 years)
•Reflective implementation
5/13/2016
AOOP / Demeter
53
Meeting the Needs
• Demeter/Java
– Easier evolution of class diagrams (with
strategy diagrams)
– Easier evolution of behavior (with visitors)
– Easier evolution of objects (with sentences)
5/13/2016
AOOP / Demeter
54
Real Life
• Used in several commercial projects
• Implemented by several independent
developers
• Used in several courses, both academic and
commercial
5/13/2016
AOOP / Demeter
55
Summary
• What has been learned: Simple UML class
diagrams, strategies and adaptive programs
• How can you apply:
– Demeter/Java takes adaptive programs as input
– Document object-oriented programs with
strategies
– Design in terms of traversals and visitors
5/13/2016
AOOP / Demeter
56
Where to get more information
• Adaptive Programming book
• UML Distilled
• Demeter/Java home page
• Course home page:
www.ccs.neu.edu/research/demeter/
course/f98
5/13/2016
AOOP / Demeter
57
Feedback
• Request feedback of training session
5/13/2016
AOOP / Demeter
58