1 The Law of Demeter By Rick Mercer with help from Object-Oriented Design Heuristics, Arthur Riel Addison-Wesley, 1996, ISBN 0-201-6338-X and Applying.

Slides:



Advertisements
Similar presentations
Software Engineering Key design concepts Design heuristics Design practices.
Advertisements

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 9 Classes.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Immutable Objects and Classes.
Stéphane Ducasse«ChapterNr».1 Arthur Riel Design Heuristics from Object-Oriented Design Heuristics by Arthur Riel Read the Heuristics… –Find reasons why.
Objects First with Java A Practical Introduction using BlueJ
March R. McFadyen1 Principle of Least Knowledge – page 265 Principle: talk only to your immediate friends Also called Law of Demeter (LoD)
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
© Wolfgang Pelz Introduction Object-Oriented Methods: Analysis, Design & Programming Dr. Wolfgang Pelz Dr. Yingcai Xiao The University of Akron.
Chapter 1 Principles of Programming and Software Engineering.
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.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 9 Thinking in Objects.
CO320 Introduction to Object- Oriented Programming Michael Kölling 3.0.
1 Observer Design Pattern By Eric Perret Pages in Applying UML and Patterns.
PRESENTED BY SANGEETA MEHTA EECS810 UNIVERSITY OF KANSAS OCTOBER 2008 Design Patterns.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Inheritance. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 Inheritance Inheritance is a fundamental object-oriented design technique used to.
CSc 335: Three More OO Design Principles
1/19 Component Design On-demand Learning Series Software Engineering of Web Application - Principles of Good Component Design Hunan University, Software.
“Enhancing Reuse with Information Hiding” ITT Proceedings of the Workshop on Reusability in Programming, 1983 Reprinted in Software Reusability, Volume.
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.
Object Oriented Design and Programming Alan Goude Room: Sheaf 9323.
1 OO Design Novosoft, 2001 by V. Mukhortov. 2 OO Design Goals  Flexibility Changes must be localized  Maintainability Modules requiring changes can.
5.0 Objects First with Java A Practical Introduction using BlueJ Introduction to Computer Science I Instructor: Allyson Anderson.
1 SAD2 - UML 4 th Lecture Class Diagram in Construction Phase Patterns Case Study Lecturer: Dr Dimitrios Makris
SOEN 6011 Software Engineering Processes Section SS Fall 2007 Dr Greg Butler
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Copyright © Craig Larman All Rights Reserved Responsibility-Driven Design with the GRASP Patterns.
S.Ducasse Stéphane Ducasse 1 Design Heuristics.
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.
OBJECT-ORIENTED PROGRAMMING (OOP) WITH C++ Instructor: Dr. Hany H. Ammar Dept. of Electrical and Computer Engineering, WVU.
Object Orientation What, How and Why Will van Beek Independent Consultant 18 march 2012.
1 Single Responsibility Principle Open Closed Principle Liskov Substitution Principle Law of Demeter CSC 335: Object-Oriented Programming and Design.
1 Software Development By Rick Mercer with help from these sources: Rational Unified Process Computing Fundamentals with C++, Rick Mercer Designing Object.
OO Design Principles Copyright © Vyacheslav Mukhortov, Nikita Nyanchuk-Tatarskiy, Copyright © INTEKS LLC,
Chapter 10 Classes and Objects In-Depth. Chapter 10 A class provides the foundation for creating specific objects, each of which shares the general attributes,
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
5.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
1 By Rick Mercer with help from Object-Oriented Design Heuristics, Arthur Riel Coupling / Cohesion.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
High Cohesion Low Coupling Old Standards for Object Oriented Programming.
Design Patterns. 1 Paradigm4 Concepts 9 Principles23 Patterns.
Evaluating an Object-Oriented Design ©SoftMoore ConsultingSlide 1.
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Object Oriented Analysis and Design 1 CREATED BY RUONAN RAO Object-Oriented Analysis and Design.
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.
Principles of Object Oriented Design
Copyright © Craig Larman All Rights Reserved COMP-350 Object-Oriented Analysis and Design GRASP: Designing Objects with Responsibilities Reference:
Programming. To gain a sound knowledge of programming principles To gain a sound knowledge of object- orientation To be able to critically assess the.
Object-Oriented Software Engineering Practical Software Development using UML and Java Modelling with Classes.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
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.
CSHenrik Bærbak Christensen1 Flexibility and Maintainability And their metrics: coupling and cohesion.
6.0 Objects First with Java A Practical Introduction using BlueJ David J. Barnes Michael Kölling.
Copyright © Craig Larman All Rights Reserved Large-Scale System Partitioning.
Mantas Radzevičius ifm-2/2
Relationships amongst Objects
Objects First with Java A Practical Introduction using BlueJ
The Law of Demeter (LoD) and how it should be used
The Law of Demeter (LoD) and how it should be used
GRASP : Designing Objects with Responsibilities
Objects First with Java A Practical Introduction using BlueJ
Code Smells 1.
AP/DJ AP: a generic technology
Producing Production Quality Software
Objects First with Java A Practical Introduction using BlueJ
Objects First with Java A Practical Introduction using BlueJ
Law of Demeter (LoD) 7/23/2019 LoD
Object Oriented System Design Responsibilities
Presentation transcript:

1 The Law of Demeter By Rick Mercer with help from Object-Oriented Design Heuristics, Arthur Riel Addison-Wesley, 1996, ISBN X and Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and Iterative Development, Craig Larman Third Edition, Pearson PTR, October 2004

2 Law of Demeter  A style rule for designing object-oriented systems  "Only talk to your immediate friends"  Name of the Greek Goddess of Agriculture  In other words, grow software in small steps  Each module should have only limited knowledge about other modules  Those "closely" related to the current unit  Each module only talks to friends  “Don't talk to strangers”

3 Law of Demeter  This is low coupling in software engineering made more explicit  Try to avoid knowing about the structure of indirect objects  Use the direct object that you need to know about and let that object talk to indirect objects

4 Who are closely related friends?  From a method, messages can be sent to  this object  a parameter of the method  an instance variable of this object  an object created within the method

5 FRIENDS

6 An Example  Widely used in big projects, for example, at JPL for the Mars exploration software, the quote  The Law of Demeter … has taken a firm hold in many areas of JPL. Major systems which have used LoD extensively include … Mars Pathfinder Software (begun in 1993). We are going to use LoD as a foundational software engineering principle for the X2000 Europa orbiter mission.

7 Grady Booch 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.

8 Abstract example class A { private B b = new B(); public void m() { this.b.c.foo(); // High coupling, bad } class B { C c; // Package protected } class C { public void foo() { }

9 Possible Test Question  Which code represents the better design, a or b?__ // a. dog.body.tail.wag(); // b. dog.expressHappiness();  The bad example couples dog to two indirect classes DogBody, and DogTail  The good design couples dog only to the direct class DogAnimal