Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 5 Bend or Break. Life does not stand still We need to make every effort to write code that is as loose – as flexible – as possible Reversability:

Similar presentations


Presentation on theme: "Chapter 5 Bend or Break. Life does not stand still We need to make every effort to write code that is as loose – as flexible – as possible Reversability:"— Presentation transcript:

1 Chapter 5 Bend or Break

2 Life does not stand still We need to make every effort to write code that is as loose – as flexible – as possible Reversability: how to make reversible decisions

3 Bend or Break Decoupling and the Law of Demeter –Keep separate concepts separate Write less: good way to stay flexible Metaprogramming: how to move details out of the code completely Temporal Coupling: do not depend on absolute time

4 Bend or Break Just a view: decouple models from views. Blackboards: provide a meeting place where modules exchange data.

5 Decoupling and the Law of Demeter Writing shy code (see also Orthogonality and Design by Contract)

6 Object Form of LoD Definition OF-LoD: A OF-LoD join point is a method-call join point, in which the target object is either: An instance variable of the "this" object. Constructed by the method. An argument of the method. Returned by a message send to “this”.

7 E-X-Violation X: a property on join points; e.g. OF-LoD. Definition E-X-Violation: A method-call in P is a X-violation if there exists an execution of P where a join point corresponding to the method-call does not satisfy property X.

8 A program P satisfies X if for all method- calls in P and all executions of P, the join points corresponding to the method-calls satisfy property X. A program P satisfies X for execution E if for all method-calls in P, the corresponding join points of E satisfy property X.

9 Object Form Violation OF-Lod-Violation: X = OF-LoD.

10 Class Form of LoD Definition CF-LoD: A CF-LoD joinpoint is a method-call join-point, in which the target object’s class is either: The static type of an instance variable. The static type of a newly constructed object. The type of an argument of the method. The return type of a method of the class.

11 Class Form Violation CF-Lod-Violation: X = CF-LoD.

12 Forms of LoD formsclass (c)object (o) static(s), Prog. Anal. useful (c/s), simple definition useful (o/s), approximates o/d dynamic(d), AspectJ not useful (c/d), c/s instead most useful (o/d), simple definition

13 Notes o/s: if an illegal message sending is possible assuming each decision taken both ways and each loop is executed 0 or more times. c/d: not interesting, because c/s. If dynamically: do o/d

14 Note The following: aFoo.getPart().getPart(). getBar().getBp().test(); Should not be allowed in a static method. Next follows a generalization of LoD to static methods (slide after next). Do you agree?

15 Within a method, messages can only be sent to the following objects: 1. A parameter of the method, including the enclosing object (this or self); 1.1. For pragmatic reasons: a global object; 2. An immediate part object (computed or stored): 2.1 An object that a method called on the enclosing object returns, including attributes of the enclosing object; 2.2 An element of a collection which is an attribute of the enclosing object; 3. An object created within the method. Object form for regular methods

16 Within a static method, messages can only be sent to the following objects: 1. A parameter of the method, including the current class; 1.1. For pragmatic reasons: a global object; 2. An immediate static part object (computed or stored): 2.1 An object that a static method called on the current class returns, including static attributes of the current class; 2.2 An element of a collection which is a static attribute of the current class; 3. An object created within the method. Object form for static methods


Download ppt "Chapter 5 Bend or Break. Life does not stand still We need to make every effort to write code that is as loose – as flexible – as possible Reversability:"

Similar presentations


Ads by Google