Law of Demeter (LoD) 7/23/2019 LoD

Slides:



Advertisements
Similar presentations
Design Patterns.
Advertisements

Unnat-e Infotech 1 Object Oriented Concepts Introduction.
February R. McFadyen1 Polymorphism Indirection Pure Fabrication Protected Variations (Law of Demeter) More GRASP Patterns.
Reviews for Exam 1 Chapter 1-4 CSc 212 Data Structures, Sec FG CCNY, Fall 2010.
What is the Chain? It’s a behavioral design pattern. It deals with how objects make requests and how they are handled.
Reviews for Exam 1 Chapter 1-4 CS 211 Data Structures MHC, 2007.
March R. McFadyen1 Principle of Least Knowledge – page 265 Principle: talk only to your immediate friends Also called Law of Demeter (LoD)
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 1.
Fall 2009ACS-3913 R. McFadyen1 Protected Variations Principle: How do you design so that variations in the future do not have an undesirable affect on.
Chapter 25 More Design Patterns.
CSc 335: Three More OO Design Principles
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
Design Dan Fleck CS 421 George Mason University. What is the design phase? Analysis phase describes what the system should do Analysis has provided a.
1 OO Design Novosoft, 2001 by V. Mukhortov. 2 OO Design Goals  Flexibility Changes must be localized  Maintainability Modules requiring changes can.
Object-Oriented Modeling and Design
Slide 1 UML Review Chapter 2: Introduction to Object-Oriented Systems Analysis and Design with the Unified Modeling Language, Version 2.0 Alan Dennis,
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
By Xiangzhe Li Thanh Nguyen.  Introduction  Terminology  Architecture  Component  Connector  Configuration  Architectural Style  Architectural.
1 4/97 Object-Oriented Design Workshop Week 6: Some Patterns for Implementing Associations, Part 1 David Van Camp Object Technology Consultant Software.
Chapter 17. Initial Object Design Inputs: requirements meetings various Use Cases – 10% complete Key risks addressed with preliminary programming System.
Sept Ron McFadyen1 UML & Design Patterns Course outlineoutline /3 Advanced Systems Design.
AP/DJ AP: a generic technology DJ: a low-learning-curve implementation of AP.
Object Oriented Programming Lecture 9: OO Design.
A Validation of Object-Oriented Design Metrics As Quality Indicators Basili et al. IEEE TSE Vol. 22, No. 10, Oct. 96.
Copyright © 2010 Pearson Education, Inc. publishing as Prentice HallChapter Writing and Completing Reports and Proposals.
Copyright © 2010 Pearson Education, Inc. publishing as Prentice HallChapter Writing Reports and Proposals.
1 The Modular Structure of Complex Systems Presented by: SeyedMasoud Sadjadi and Wei Zhu David L. Parnas, Paul C. Clement, and David M. Weiss ICSE 1984.
Law of Demeter. What is it: Style Rule for building systems. Proposed by my research group: The Demeter Research Group in 1987, published in Covered.
SWE © Solomon Seifu ELABORATION. SWE © Solomon Seifu Lesson 12-5 Software Engineering Design Goals.
Not only mark-up languages! There are other many other grammar formalisms and tools than XML. Some of them standardized (ASN). Even XML does not always.
Copyright © 2002 by Pearson Education, Inc., publishing as Longman Publishers. All rights reserved Technical Communication: Strategies for College and.
1 Single Responsibility Principle Open Closed Principle Liskov Substitution Principle Law of Demeter CSC 335: Object-Oriented Programming and Design.
Object-oriented Design and Programming CS 2210: SW Development Methods Reading: Chapter 2 of MSD text – Section on UML: look at class diagrams but.
OO Design Principles Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, Copyright © INTEKS LLC,
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Design Pattern Catalog - Page L3-1 PS95&96-MEF-L10-1 Dr. M.E. Fayad Creationa.
ITEC324 Principle of CS III Chapter 2 (Horstmann’s Book) – Part 1 The Object-Oriented Design Process Hwajung Lee.
Advanced Object-Oriented Design Patterns and Architectures Part One COEN396A John Xiao
M1G Introduction to Programming 2 3. Creating Classes: Room and Item.
Evaluating an Object-Oriented Design ©SoftMoore ConsultingSlide 1.
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:
Design. Practices Principles Patterns What are the characteristics of good design? What are good solutions to common design problems? How do we go about.
Example to motivate discussion We have two lists (of menu items) one implemented using ArrayList and another using Arrays. How does one work with these.
Watching the movie the hard way…. Page 256 – Head First Design Patterns.
PowerPoint Presentation for Dennis, Wixom, & Tegarden Systems Analysis and Design with UML, 3rd Edition Copyright © 2009 John Wiley & Sons, Inc. All rights.
The Law of Demeter For Operating System Course. Motivation Several programs were written in bad style Are difficult to maintain There is a simple remedy.
Talk only to your friends that share the same concerns (Law of Demeter for Concerns) Midterm Review February 2004.
1 The Law of Demeter By Rick Mercer with help from Object-Oriented Design Heuristics, Arthur Riel Addison-Wesley, 1996, ISBN X and Applying.
6.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Engineered for Tomorrow Unit:8-Idioms Engineered for Tomorrow sharmila V Dept of CSE.
AP/DJ AP: a generic technology
Mantas Radzevičius ifm-2/2
Jim Fawcett CSE776 – Design Patterns Summer 2005
Objects First with Java A Practical Introduction using BlueJ
Design Points - Law of Demeter
Introduction to the Unified Modeling Language
MPCS – Advanced java Programming
Basic Concepts in Software Design
Chapter 1-4 CSc 212 Data Structures, Sec AB CCNY, Spring 2012
The Law of Demeter (LoD) and how it should be used
The Law of Demeter (LoD) and how it should be used
What is an Architecture?
ADAPTIVE PROGRAMMING Sezen ERDEM December 2005.
Introduction to the Unified Modeling Language
Introduction to the Unified Modeling Language
AP/DJ AP: a generic technology
Karl J. Lieberherr Northeastern University College of Computer Science
Lecture 21: Crosscutting Aspect-Oriented Programming Background
The Big Thirst Part 3.
Adaptive Programming in JAsCo
Chapter 1-4 CSc 212 Data Structures, Sec FG CCNY, 2009
Presentation transcript:

Law of Demeter (LoD) 7/23/2019 LoD Copyright, 1996 © Dale Carnegie & Associates, Inc.

Law of Demeter Style Rule for building systems Proposed by my research group: The Demeter Research Group in 1987, published in 1988 Covered in many major books on OO 7/23/2019 LoD

Citibank Quote: Law of Demeter The Law of Demeter forms one of the cornerstones of the design approach of the Global Finance Application Architecture (quote from: Global Finance Application Architecture: Business Elements Analysis, Oct. 1991, Citibank confidential document) Widely used in big projects, for example, at JPL for the Mars exploration software. 7/23/2019 LoD

Law of Demeter Principle Each unit should only use a limited set of other units: only units “closely” related to the current unit. “Each unit should only talk to its friends.” “Don’t talk to strangers.” Motivation: Control information overload. We can only keep a limited set of items in short-term memory of our minds. 7/23/2019 LoD

Law of Demeter FRIENDS 7/23/2019 LoD

Application to OO Unit = method closely related = methods of class of this/self and other argument classes methods of immediate part classes (classes that are return types of methods of class of this/self) In the following we talk about this application of the Law of Demeter Principle to OO 7/23/2019 LoD

What others say about the Law of Demeter Booch Rumbaugh 7/23/2019 LoD

Booch and the Law of Demeter Context Chapter: Classes and Objects, Section: On Building Quality Classes and Objects, Subsection: Choosing Relationships 7/23/2019 LoD

Booch and the Law of Demeter Quote: The basic effect of applying this Law is the creation of loosely coupled classes, whose implementation secrets are encapsulated. Such classes are fairly unencumbered, meaning that to understand the meaning of one class, you need not understand the details of many other classes. 7/23/2019 LoD

Rumbaugh and the Law of Demeter Context Chapter: Programming Style, Section: Extensibility 7/23/2019 LoD

Rumbaugh and the Law of Demeter Quote: Avoid traversing multiple links or methods. A method should have limited knowledge of an object model. A method must be able to traverse links to obtain its neighbors and must be able to call operations on them, but it should not traverse a second link from the neighbor to a third class. 7/23/2019 LoD

Agreement that LoD Good Idea How to eliminate violations of LoD: good solutions exist but not widely known. Two approaches to elimination: OO approach Adaptive approach APPC approach Demeter/Java approach 7/23/2019 LoD

Law of Demeter FRIENDS 7/23/2019 LoD

What if your friends are far away? You pay them to travel to you or you send an agent to them to collect the information you need. Approximate Directions: You give them or your agent directions about what kind of information to collect but you don’t care about accidental details of the travel. Detailed Directions: You give them or your agent detailed travel directions. 7/23/2019 LoD

The Law of Demeter (cont.) Violation of the Law class A {public: void m(); P p(); B b; }; class B {public: C c; }; class C {public: void foo(); }; class P {public: Q q(); }; class Q {public: void bar(); }; void A::m() { this.b.c.foo(); this.p().q().bar();} 7/23/2019 LoD

Violations: Dataflow Diagram 2:c foo() 1:b B C A 4:q() bar() 3:p() P Q 7/23/2019 LoD

Law of Demeter C A FRIENDS S X B From S to A From S to B From S via X to C 7/23/2019 LoD

Adaptive Elimination of Violation of the Law void A::m(ClassGraph cg) { (C) cg.fetch(this,”from A to C”).foo(); (Q) cg.fetch(this,”from A to Q”).bar();} void A::m() { this.b.c.foo(); this.p().q().bar();} // violation 7/23/2019 LoD

OO:Elimination of Violation foo2 c foo() 1:b B C A 2:foo2() 4:bar2() bar2 bar() 3:p() q() P Q 7/23/2019 LoD