1 / 16

Chapter 5

Chapter 5. Bend or Break. 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: how to make reversible decisions. Bend or Break. Decoupling and the Law of Demeter Keep separate concepts separate

dewey
Download Presentation

Chapter 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 5 Bend or Break

  2. 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: 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

  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. Object form for regular methods • 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.

  16. Object form for static methods • 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.

More Related