Presentation is loading. Please wait.

Presentation is loading. Please wait.

Review lecture AOO/Demeter.

Similar presentations


Presentation on theme: "Review lecture AOO/Demeter."— Presentation transcript:

1 Review lecture AOO/Demeter

2 Review Use of strategies for programming
traversals for general behavior traversals for specialized behavior object marshaling (distributed computing) persistent objects, query languages (data bases) Use of strategies for specification Object Constraint Language (OCL), define collections, describe growth phases 11/22/2018 AOO

3 Lecture 1 11/22/2018 AOO

4 Overview good separation of concerns is the goal
concerns should be cleanly localized programs should look like designs Big picture 11/22/2018 AOO

5 Cross-cutting of components and aspects
better program ordinary program structure-shy functionality Components structure Aspect 1 avoid tangled programs AOP synchronization Aspect 2 11/22/2018 AOO

6 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 11/22/2018 AOO

7 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 problem solved by traversal strategies 11/22/2018 AOO

8 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 ideas can be used without tools Applicable to design and documentation of your current systems. 11/22/2018 AOO

9 Pattern Language for Adaptive Programming (AP)
Karl Lieberherr Northeastern University Meaning of Adaptive: Program is split into at least two parts. P = W(S , B). B makes assumptions on S. P1 = W(S1, B). change first part S of program to S1 and the second, which depends on the first, stays unchanged. The second program P1 is very different from P. The second part B adapts to changes of the first. Lecture 2, 1. class, fall 97, sep 25. 11/22/2018 AOO

10 Introduction Four Patterns Structure-shy Traversal Selective Visitor
Structure-shy Object Class Graph Structure is viewed as a separate “module”. 11/22/2018 AOO

11 Lecture 2 11/22/2018 AOO

12 Structure-shy object pattern
Parsing, class graphs etc. separation of concerns: sentences : robust representation objects : brittle representations grammars: rules for constructing brittle rep. from robust rep. 11/22/2018 AOO

13 Parsing Inherent problem: There is no algorithm to check for ambiguity. Shown by reduction: Could solve other undecidable problems. Invent condition which is stronger than non-ambiguity and which can be checked efficiently. Ok. to exclude some non-ambiguous grammars. LL(1) conditions. 11/22/2018 AOO

14 Better separation of concerns
An old topic: Dijkstra 1976 Avoid or minimize tangling 11/22/2018 AOO

15 Two types of concerns Generic concerns Behaviors structure
coordination remote invocation exception handling efficiency interoperability Behaviors sum check print translate 11/22/2018 AOO

16 The source of tangling Alignment with classes would be nice, but...
11/22/2018 AOO

17 The source of tangling ...issues cross-cut classes 11/22/2018 AOO
Cut this psrt? ...issues cross-cut classes 11/22/2018 AOO

18 Code tangling is bad Harms program structure
Distracts from main functionality Hard to program, error-prone Code difficult to understand, maintain 11/22/2018 AOO

19 Container capacity checking
improve Initial visitor 11/22/2018 AOO

20 Container capacity problem
Refined visitor class graph CheckingVisitor = <iV> InitialVisitor <violations> int. InitialVisitor = <sV> SummingVisitor <diff> int // communication <stack> Stack. // from java.util.*; SummingVisitor = <total> int. 11/22/2018 AOO

21 CheckingVisitor init (@ violations = 0; @)
after Container diff = // use iV cap = host.get_capacity() if (diff > cap) violations = violations + return int need to give return type since Demeter/Java does not analyze code between 11/22/2018 AOO

22 InitialVisitor init (@ stack = new Stack(); @)
before Container stack.push(… sV.get_total() after Container diff = … (Integer) stack.pop() - sV.get_total() 11/22/2018 AOO

23 Third lecture Review Visitor pattern Demeter/Java programming
Adaptive behavior Debugging class dictionaries Traversal strategies 11/22/2018 AOO

24 Agenda for Adaptive Object-Oriented Software/Demeter
Adaptive Programming Aspect-Oriented Progr. Demeter/Java Java Java environment UML strategy graphs class graphs object graphs state graphs principles heuristics patterns idioms theorems algorithms requirements domain analysis design implementation use cases interfaces traversals visitors packages Demeter Method iterative development spiral model 11/22/2018 AOO

25 Adaptive Methods strategy/visitor class names
no need to reuse visitor objects? no need to reuse strategy/visitor combination? int countInhRels() via Alternat to Vertex (CountingVisitor); return value of first visitor class works only if visitors are not nested encourages self-contained visitor classes 11/22/2018 AOO

26 Lecture 4 11/22/2018 AOO

27 Specification and Efficient Implementation (Graph Theory of OOP/OOD)
Traversal Strategies Specification and Efficient Implementation (Graph Theory of OOP/OOD) 11/22/2018 AOO

28 Overview Use structure in graphs to express subgraphs and path sets in those graphs. Gain: writing programs in terms of strategies yields shorter and more flexible programs. Does not work well on dense graphs and graphs with self loops. 11/22/2018 AOO

29 Learning map correspondences graph paths labeled FROM-TO computation
generalization Learning map other relationships numbers: order of coverage correspondences X:class path - concrete path Y:object path - concrete path traversal path - class path 8 1 graph paths labeled FROM-TO computation 3 2 5 9 10 object graph class graph strategy graph traversal graph propagation graph 4 6 object traversal defined by concrete path set name map constraint map 11 zig-zags short-cuts 7 Algorithm 1 in: strategy + class graph out: traversal graph 12 Algorithm 2 in: traversal + object graph out: object traversal 11/22/2018 AOO

30 Compilation of strategies
Idea of traversal graph: Paths defined by from A to B can be represented by a subgraph of the class graph. Compute all edges reachable from A and from which B can be reached. Edges in intersection form graph which represents traversal. Generalize to any strategies: Need to use big graph but above from A to B approach will work. 11/22/2018 AOO

31 Strategy behind Strategy
Instead of developing a specialized algorithm to solve a specific problem, modify the data until a standard algorithm can do the work. May have implications on efficiency. In our case: use FROM-TO computation. 11/22/2018 AOO

32 Why k copies? Mimics using k distinct traversal method names.
Run-time traversals need enough state information. 11/22/2018 AOO

33 Short-cut abstract representation of traversal code strategy:
B -> C} class graph class graph A A start set traversal method t2 traversal method t x x c c 0..1 0..1 b b b B X X B x x c c finish set C C thick edges with incident nodes: traversal graph 11/22/2018 AOO

34 Short-cut A( <x> X( <b> B( <c> C())) strategy:
{A -> B B -> C} Object graph Traversal graph A( <x> X( <b> B( <c> C())) A start set x 0..1 b b X X B x c finish set C 11/22/2018 AOO

35 Short-cut A( <x> X( <b> B( <c> C())) strategy:
{A -> B B -> C} Object graph Traversal graph A( <x> X( <b> B( <c> C())) A start set x 0..1 b b X X B x c finish set C Used for token set and currently active object 11/22/2018 AOO

36 Short-cut A( <x> X( <b> B( <c> C())) strategy:
{A -> B B -> C} Object graph Traversal graph A( <x> X( <b> B( <c> C())) A start set x 0..1 b b X X B x c finish set C Used for token set and currently active object 11/22/2018 AOO

37 Short-cut A( <x> X( <b> B( <c> C())) strategy:
{A -> B B -> C} Object graph Traversal graph A( <x> X( <b> B( <c> C())) A start set x 0..1 b b X X B x c finish set C Used for token set and currently active object 11/22/2018 AOO

38 Short-cut A( <x> X( <b> B( <c> C())) strategy:
{A -> B B -> C} Object graph Traversal graph A( <x> X( <b> B( <c> C())) A start set x 0..1 b b X X B x c finish set C Used for token set and currently active object 11/22/2018 AOO

39 Short-cut A( <x> X( <b> B( <c> C())) strategy:
{A -> B B -> C} Object graph Traversal graph A( <x> X( <b> B( <c> C())) A start set x 0..1 b b X X B x c finish set C Used for token set and currently active object 11/22/2018 AOO

40 Short-cut A( <x> X( <b> B( <c> C())) strategy:
{A -> B B -> C} Object graph Traversal graph A( <x> X( <b> B( <c> C())) A start set x 0..1 b b X X B x c finish set C Used for token set and currently active object After going back to X 11/22/2018 AOO

41 Zig-zags strategy graph with name map class graph B D A E B C G A C D
F B D F D E F <A C D E G> is excluded traversal graph = strategy graph (essentially) G 11/22/2018 AOO

42 Zig-zags A( B( D( E( G()) F( G()))) C( G())))) strategy graph
with name map class graph A( B( D( E( G()) F( G()))) C( G())))) A B D object tree E B C G A C D F D B D F E F <A C D E G> is excluded G traversal graph = strategy graph (essentially) 11/22/2018 AOO

43 Zig-zags A( B( D( E( G()) F( G()))) C( G())))) strategy graph
with name map class graph A A( B( D( E( G()) F( G()))) C( G())))) object tree B D E B C G A C D F D B D F E F <A C D E G> is excluded G traversal graph = strategy graph (essentially) 11/22/2018 AOO

44 Zig-zags A( B( D( E( G()) F( G()))) C( G())))) strategy graph
with name map class graph A( B( D( E( G()) F( G()))) C( G())))) A object tree B D E B C G A C D F D B D F E F <A C D E G> is excluded G traversal graph = strategy graph (essentially) 11/22/2018 AOO

45 Zig-zags A( B( D( E( G()) F( G()))) C( G())))) strategy graph
with name map class graph A A( B( D( E( G()) F( G()))) C( G())))) object tree B D E B C G A C D F D B D F E F <A C D E G> is excluded G traversal graph = strategy graph (essentially) 11/22/2018 AOO

46 Zig-zags A( B( D( E( G()) F( G()))) C( G())))) strategy graph
with name map class graph A A( B( D( E( G()) F( G()))) C( G())))) object tree B D E B C G A C D F D B D F E F <A C D E G> is excluded G traversal graph = strategy graph (essentially) 11/22/2018 AOO

47 Zig-zags A( B( D( E( G()) F( G()))) C( G())))) strategy graph
with name map class graph A( B( D( E( G()) F( G()))) C( G())))) A object tree B D E B C G A C D F D B D F E F <A C D E G> is excluded G traversal graph = strategy graph (essentially) 11/22/2018 AOO

48 Zig-zags A( B( D( E( G()) F( G()))) C( G())))) strategy graph
with name map class graph A( B( D( E( G()) F( G()))) C( G())))) A object tree B D E B C G A C D F D B D F E F <A C D E G> is excluded G traversal graph = strategy graph (essentially) 11/22/2018 AOO

49 Zig-zags A( B( D( E( G()) F( G()))) C( G())))) strategy graph
with name map class graph A( B( D( E( G()) F( G()))) C( G())))) A object tree B D E B C G A C D F D B D F E F <A C D E G> is excluded G traversal graph = strategy graph (essentially) 11/22/2018 AOO

50 Zig-zags A( B( D( E( G()) F( G()))) C( G())))) strategy graph
with name map class graph A( B( D( E( G()) F( G()))) C( G())))) A object tree B D E B C G A C D F D B D F E F <A C D E G> is excluded G traversal graph = strategy graph (essentially) 11/22/2018 AOO

51 Simplifications of algorithm
If no short-cuts and zig-zags, can use propagation graph. No need for traversal graph. Faster traversal at run-time. Presence of short-cuts and zig-zags can be checked efficiently (compositional consistency). See chapter 15 of AP book. 11/22/2018 AOO

52 Lecture 5 Growth plan pattern Class graph transformations
object-preserving extending weakly extending language preserving language extending Primitive transformations 11/22/2018 AOO

53 Growth plan behavior phases L1 Í L2 Í L3 structure, grammar phases P4
(P0, P1) (P2,P3) (P4) 11/22/2018 AOO

54 Growth plan Consequences: Following Growth plan has a number of benefits: Gradual building of confidence in your software development skills. Show prototypes to your customers. Simplified testing. Find earliest phase where a bug shows up. faster compilation and generation 11/22/2018 AOO

55 Example Same adaptive program for Terminal
Buffer Rule checking works for both phases. Faster for phase 1. Cd_graph = <first> Adj. Adj = <vertex> Vertex <ns> Construct “.”. Construct = “=“ <l1> Labeled_vertex <l2> Labeled_vertex. Labeled_vertex = “<“ <label_name> Ident “>“ <class_name> Vertex. Vertex = <name> Ident. phase 1 Cd_graph = <first> Adj <rest> Adj_list. Adj = <vertex> Vertex <ns> Neighbors “.”. Neighbors : Construct | Alternat. Construct = “=“ <c_ns> Any_vertex_list. Labeled_vertex = “<“ <label_name> Ident “>“ <class_name> Vertex. Vertex = <name> Ident. Any_vertex_list = <first> Any_vertex <rest> Any_vertex_list. Any-Vertex : Labeled_vertex | Syntax_vertex. ... phase 2 11/22/2018 AOO

56 Lecture 6 Coordination aspect Aspect-oriented programming 11/22/2018
AOO

57 Demeter/Java COOL class _Cool_Lock_
need instance of this class for each method which appears in a mutex set 11/22/2018 AOO

58 Implementation of mutex sets
f,g,h,i mutex (f,g) mutex (f, h) mutex ( g,h,i) g f Immediate successors tell us which methods to watch i h 11/22/2018 AOO

59 Implementation of mutex sets
f,g,h,i,j mutex (f,g) mutex (f, h) mutex ( g,h,i) mutex (f, i,j) g f Immediate successors tell us which methods to watch j i h 11/22/2018 AOO

60 Implementation of mutex sets
f,g,h,i,j mutex (f,g) mutex (f, h) mutex ( g,h,i) mutex (f, i,j) use hypergraph instead Advantage: complete graph with n nodes is not represented by binomial(n,2) edges. Quadratic growth is avoided. set of hyperedges incident with a node tells us which methods to watch f g j i h 11/22/2018 AOO

61 Lecture 7 Demeter/Java notation for strategies
traversal dependent roles Metric for structure-shyness Finding strategies Demeter Method Law of Demeter Demeter Process 11/22/2018 AOO

62 Lecture 7 Project (from UML Distilled) Class dictionary kinds
AP and structural design patterns 11/22/2018 AOO

63 Traversal dependent roles
Class graph with super-imposed strategy graph Strategy graph Person 3a Person 4a Brothers bypassing exists Married 4b Sisters 2 3b spouse: Person Status 1 Sisters Brothers Married Single sisters_in_law: Person brothers_in_law: Person 11/22/2018 AOO

64 Forms of adaptiveness time feedback compile-time run-time with without
new 11/22/2018 AOO

65 Law of Demeter Style rule for OOP Goals
promote good oo programming style minimize coupling between classes minimize change propagation facilitate evolution 11/22/2018 AOO

66 GRASP patterns Craig Larman, Applying UML and Patterns, Prentice Hall, 1998 book. Describes nine General Responsibility Assignment Software Patterns (GRASP): Expert, Creator, Controller, Low Coupling, High Cohesion, Polymorphism, Pure Fabrication, Indirection, Don’t Talk to Strangers (Law of Demeter) 11/22/2018 AOO

67 Don’t Talk to Strangers
Solution. Assign the responsibility to a client’s direct object to collaborate with an indirect object, so that the client does not need to know about the indirect object. Problem. If an object has knowledge of the internal connections and structure of other objects, then it suffers from high coupling. 11/22/2018 AOO

68 Don’t Talk to Strangers
Discusssion. Violating this principle is common in Smalltalk: myBadMethodToGetPrice “hop along from X to A to B to C to D, to return price of D” myDirectX getA getB getC getD getprice 11/22/2018 AOO

69 Don’t Talk to Strangers
Breaking the Law. There is some kind of “broker”or “object server” that is responsible for returning other objects based upon lookup by a key value. It is acceptable to send messages to such returned objects directly. A{void f(int key){broker.lookup (key).do(); }} 11/22/2018 AOO

70 Demeter/Java OO products
Behavior Structure tree objects represented as sentences 11/22/2018 AOO

71 class dictionaries (11 kinds)
inductive nonleft-recursive 9 10 11 8 7 6 1 2 LL(1) 3 1: ideal case 2: JavaCC does not complain (Oct ). Grammar contains useless symbols. Ok if we don’t want to parse but forces cyclic objects. 4 nonambiguous 5 Venn Diagram 11/22/2018 AOO

72 Lecture 8 Style rules: Class graph minimization
Evolution of object behavior context objects Current issues in Software Engineering: The year 2000 crisis 11/22/2018 AOO

73 UML Model architecture Object Constraint Language
Lecture 9 UML Model architecture Object Constraint Language 11/22/2018 AOO

74 Three layers of Demeter
instance of 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 TP text sentence 11/22/2018 AOO

75 Improve OCL: make adaptive
OCL stresses the importance of collections Collections are best specified adaptively A strategy SS = (S, B, s, t) with source s and target set t and name map N for class graph G defines a collection of objects contained in a N(s)-object. The collection type CT is the union of N(t1) for t1 in t. 11/22/2018 AOO / UML / OCL/Strategies

76 AOO / UML / OCL/Strategies
Improve OCL The collection consists of CT-objects reached during the traversal of the N(s) object following strategy SS. 11/22/2018 AOO / UML / OCL/Strategies

77 AOO / UML / OCL/Strategies
Properties In OCL an attribute an association end an operation with isQuery true a method with isQuery true Add for adaptive OCL a strategy { … } with a single source 11/22/2018 AOO / UML / OCL/Strategies

78 UML class diagram ClassGraph
0..* Entry EParse entries ClassGraph BParse ClassDef Body parts Part className 0..* ClassName super ClassGraph -- concrete classes self.{to Concrete}->size Concrete Abstract 11/22/2018 AOO / UML / OCL/Strategies

79 AOO / UML / OCL/Strategies
Applications Number of concrete classes: ClassGraph self.entries-> select(c:Entry|c. oclIsTypeOf(ClassDef))-> collect(body)-> select (b:Body|b. oclIsTypeOf(Concrete)) ->size 11/22/2018 AOO / UML / OCL/Strategies

80 AOO / UML / OCL/Strategies
ClassGraph self.entries-> select(c:Entry|c. oclIsTypeOf(ClassDef))-> collect(body)-> select (b:Body|b. oclIsTypeOf(Concrete)) ->size -- count concrete classes ClassGraph -- count concrete classes self.{to Concrete}->size Which one is easier to write? 11/22/2018 AOO / UML / OCL/Strategies

81 The End


Download ppt "Review lecture AOO/Demeter."

Similar presentations


Ads by Google