370 likes | 382 Views
This article explores the concept of adaptive programming strategy, which allows for late binding of data structures without changing the program. It introduces the use of DJ classes, such as ClassGraph, Strategy, Visitor, ObjectGraph, and TraversalGraph, to handle data structure details on demand.
E N D
Midterm Review CSU 670 Spring 2004
AP • Late binding of data structures • Programming without accidental data structure details yet handling all those details on demand without program change
Concepts needed(DJ classes) • ClassGraph • Strategy • Visitor • ObjectGraph • TraversalGraph (efficiency) • ObjectGraphSlice (efficiency)
Adaptive Programming Strategy Bold names refer to DJ classes. is use-case based abstraction of ClassGraph defines family of ObjectGraph
Adaptive Programming Strategy defines traversals of ObjectGraph plus Strategy defines ObjectGraphSlice
Adaptive Programming Strategy guides and informs Visitor
Software Design and Development with DJ (very brief) • Functional decomposition into generic behavior • Decomposition into methods • Decomposition into formal traversal strategies • Decomposition into visitors • Adaptation of generic behavior • Identify class graph • Identify traversal strategies
Definition: Class Graph • A class graph is a directed graph with a partial order on the nodes. We write c1 -> c2 for the edges (construction edges) and c1 <= c2 for the order (inheritance edges -- c1 is a subclass of c2). • We write => for the inverse of <=.
Relations • We think of directed graphs as relations. • Write C(c1,c2) or c1 C c2 for edge from c1 to c2 in C. • Composition of relations by . E.g., x (R.S) z iff there is a y such that xRy and ySz. • R* is the reflective transitive closure of a relation R.
Strategy: From X1 to T o2:X2 o1:X1 declared type of target of e is X3 =>X2 e go down e iff X1 <=.e X3 =>.(<=.C.=>)*.<=) T if only construction edges: go down e iff X1 e X3 C* T
z Strategy S -> T x X1 Y1 Z1 y S X2 Y2 Z2 T t X3 Y3 Z3 x y z t s1:S x31:X3 y31:Y3 z31:Z3 t1:T go down e iff S <=.C X1 =>.(<=.C.=>)*.<=) T
z Strategy S -> T x X1 Y1 Z1 y S X2 Y2 Z2 T t X3 Y3 Z3 x y z t s1:S x31:X3 y31:Y3 z31:Z3 t1:T go down e iff S <=.C X1 =>.(<=.C.=>)*.<=) T
z Strategy S -> T x X1 Y1 Z1 y S X2 Y2 Z2 T t X3 Y3 Z3 x y z t s1:S x31:X3 y31:Y3 z31:Z3 t1:T <=,=> not used go down e iff S <=.C X1 =>.(<=.C.=><=.C.=><=.C=>).<=) T
strategy Example A -> T T -> D a1:A 0..1 :D r1:R X 0..1 B c1:C s1:S D A C s2:S t1:T 0..1 r2:R object graph R S T 0..1 c2:C class graph d2:D go down e iff A <=.C R =>.(<=.C.=>)*.<=) T
S = from BusRoute through Bus to Person Example 2 busStops BusRoute BusStopList buses 0..* NGasPowered BusStop BusList waiting 0..* passengers Bus PersonList Person 0..* DieselPowered
OG : BR BL DP PL P OG’: BR BL B PL P SG : BR B P Example 2 Only node paths shown for space reasons BusList Route1:BusRoute buses busStops :BusStopList Bus15:DieselPowered passengers CentralSquare:BusStop waiting :PersonList :PersonList Joan:Person Paul:Person Seema:Person Eric:Person S = from BusRoute through Bus to Person
OG : BR BL OG’: BR BL SG : BR Example 3 Only node paths shown for space reasons early termination BusList Route1:BusRoute buses busStops :BusStopList Bus15:DieselPowered passengers CentralSquare:BusStop waiting :PersonList :PersonList Joan:Person Paul:Person Seema:Person Eric:Person S = from BusRoute via NGasPoweredto Person
A simple view of traversals • When a traversal reaches a target node in the object graph, the path traversed from the source, with suitable substitution of subclasses by superclasses, must be an expansion of an s-t path in the strategy graph. s is the source and t is the target of the strategy. Each edge in the strategy graph corresponds to at least one edge in the object graph.
A simple view of traversals • When a traversal reaches a final node in the object graph without being at a target, the path traversed from the source, with suitable substitution of subclasses by superclasses, must be a prefix of an expansion of an s-t path in the strategy graph. The prefix is the longest prefix such that there is still a possibility of success as determined by the class graph.
Object Graph Slice • The object graph slice starting with o1 is the slice built by following the edges selected by the path regular expression starting at o1 and continuing until every path terminates (at an object of type t or if it terminates prematurely). go down e iff X1 <=.e X3 =>.(<=.C.=>)*.<=) T
Strategy definition:embedded, positive strategies • Given a graph G, a strategy graph S of G is any subgraph of the transitive closure of G. • The transitive closure of G=(V,E) is the graph G*=(V,E*), where E*={(v,w): there is a path from vertex v to vertex w in G}.
Transitive Closure busStops BusRoute BusStopList buses 0..* BusStop BusList waiting 0..* passengers Bus PersonList Person 0..*
Strategy graph and base graph are directed graphs Key concepts • Strategy graph S with source s and target t of a base graph G. Nodes(S) subset Nodes(G) (Embedded strategy graph). • A path p is an expansion of path p’ if p’ can be obtained by deleting some elements from p.
class dictionaries (11 kinds) inductive nonleft-recursive 9 10 11 8 7 6 1 2 LL(1) 3 4 nonambiguous 5 Venn Diagram AOO / Demeter
Patterns Patterns • Structure-shy Traversal • Selective Visitor • Structure-shy Object • Class Graph • Growth Plan Pattern
instance of Three layers of Demeter defines classes Demeter behavior and aspect files B: metamodel L: model P: user objects CB your behavior and aspect files CL metamodel OB classes model OL TB user object OP a class dictionary for class dictionaries objects TL class dictionary text TP sentence
Icon Demeter Tiling Use as reminder for Demeter Tiling. CB OBCL TBOL TLOP TP
Example ??? Demeter Tiling CB OBCL TBOL TLOP TP Basket aBasket:Basket With respect to the project class dictionary as OB
Example Vertex (or Ident) Demeter Tiling CB OBCL TBOL TLOP TP Basket aBasket:Basket With respect to the project class dictionary as OB
Example ??? Demeter Tiling CB OBCL TBOL TLOP TP Regular_Syntax aRegular_Syntax:Regular_Syntax With respect to the project class dictionary as OB = OL
Example Vertex Demeter Tiling CB OBCL TBOL TLOP TP Regular_Syntax aRegular_Syntax:Regular_Syntax With respect to the project class dictionary as OB = OL
Example ??? Demeter Tiling CB OBCL TBOL TLOP TP Labeled = <label_name> Ident ... <b> With respect to the project class dictionary as OB = OL
Example Adjacency = <source> Vertex ... Demeter Tiling CB OBCL TBOL TLOP TP Labeled = <label_name> Ident ... <b> With respect to the project class dictionary as OB = OL
Example ??? Demeter Tiling CB OBCL TBOL TLOP TP Adjacency = <source> Vertex ... A = <b> B <b> B. With respect to the project class dictionary
Example Adjacency = <source> Vertex ... Demeter Tiling CB OBCL TBOL TLOP TP Adjacency = <source> Vertex ... A = <b> B <b> B. With respect to the project class dictionary
Lightweight Software Development Method • Extreme Programming • lots of testing, write test cases early • incremental development • pair programming
UML • class diagrams • object diagrams