Smaller, More Evolvable Software: An Introduction to the Demeter Method - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

Smaller, More Evolvable Software: An Introduction to the Demeter Method

Description:

... for example, at JPL for the Mars exploration software. ... Mars Pathfinder Software (begun in 1993) ... Traversal.long_get(this,'A- Q').bar();} void A::m ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 33
Provided by: karllie
Category:

less

Transcript and Presenter's Notes

Title: Smaller, More Evolvable Software: An Introduction to the Demeter Method


1
Smaller, More Evolvable Software An Introduction
to the Demeter Method
  • Karl J. Lieberherr
  • Northeastern University
  • College of Computer Science
  • lieber_at_ccs.neu.edu/www.ccs.neu.edu/home/lieber

2
Overview
  • Introduction to Demeter
  • Law of Demeter Principle
  • How it was used at Citibank, JPL etc.

3
Thanks to Industrial Collaborators/Sponsors
  • IBM Theory of contracts, Adaptive Programming
  • Citibank, SAIC Adaptive Programming
  • Mettler Toledo OO Evolution
  • Xerox PARC Aspect-Oriented Programming (Gregor
    Kiczales et al.)
  • supported by DARPA (EDCS) and NSF

4
What is Demeter
  • A high-level interface to object-oriented
    programming and specification systems
  • Demeter System/OPL
  • Demeter Method Demeter Tools/OPL
  • So far OPL Java, C, Perl, Borland Pascal,
    Flavors
  • Demeter Tools/OPL Demeter/OPL

5
History
1987
  • Law of Demeter
  • First traversal specifications
  • Fast and general compilation algorithm
  • APPCs (Adaptive Plug-and-Play Components)

1990
1996/97
1998
6
Law of Demeter
  • What is it 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 design and
    programming.

7
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.
    Dont talk to strangers.
  • Main Motivation Control information overload. We
    can only keep a limited set of items in
    short-term memory.

8
Law of Demeter
FRIENDS
9
closely related
10
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 example
    follows in a few slides.

11
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.

12
Jet Propulsion Laboratory(JPL) Quote Law of
Demeter
  • 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.

13
What others say about the Law of Demeter
  • Two examples
  • Booch
  • Rumbaugh

14
Booch and the Law of Demeter
  • Context
  • Chapter Classes and Objects, Section On
    Building Quality Classes and Objects, Subsection
    Choosing Relationships

15
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.

16
Rumbaugh and the Law of Demeter
  • Context
  • Chapter Programming Style, Section Extensibility

17
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.

18
Law of Demeter(alternative formulation)
  • A method should have limited knowledge of an
    object model.
  • Leads to another Demeter favorite Use grammars
    to define both class structure and an
    application-specific language. See the
    Structure-Shy Object Pattern.

19
Agreement that LoD Good Idea
  • How to follow LoD good solutions exist but not
    widely known. Two approaches to following LoD
  • OO approach
  • Adaptive approaches
  • Traversal support
  • APPC
  • Demeter/Java

20
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 Am()
  • this.b.c.foo() this.p().q().bar()

21
Violations Dataflow Diagram
m
foo()
2c
1b
B
C
A
4q()
bar()
3p()
P
Q
22
OO Following of LoD
m
foo2
foo()
c
1b
B
C
A
2foo2()
4bar2()
bar2
bar()
3p()
q()
P
Q
23
Adaptive Following of LoD
  • void Am()
  • (C)
  • Traversal.long_get(this,A-gtC).foo()
  • (Q)
  • Traversal.long_get(this,A-gtQ).bar()
  • void Am()
  • this.b.c.foo() this.p().q().bar() //
    violation

24
Law of Demeter
FRIENDS
25
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 dont care about accidental
    details of the travel.
  • Detailed Directions You give them or your agent
    detailed travel directions.

26
Adaptive Following LoD
C
A
FRIENDS
a
S
X
c
b
aFrom S to A bFrom S to B cFrom S via X
to C
27
Traversal strategies create friends
  • Class Traversal is an intermediate class between
    classes that need to communicate

Traversal.long_get(Object o, Strategy s)
28
Are not friends for accidental reasons
  • Other classes exist for other reasons
  • Ideal class graph all are friends, even far
    away classes.

29
Adaptive Following LoD Key idea
  • Introduce an ideal class graph
  • Write current behavior in terms of ideal class
    graph
  • Map ideal class graph flexibly into concrete
    class graph using traversal strategies

30
Adaptive Following of LoD Key Idea
31
Motivation
OOAD
Collab-1
Z
C1
C4
C2
C3
C5
Collab-4
Collab-2
Collab-3
Implementation
  • --gt Tangling

32
What is the Problem?
OO technology has not met its expectations
when applied to real business applications partly
due to the fact that there is no place
where to put higher-level operations which
affect several objects. if built into the
classes involved, it is impossible to get an
overview of the control flow. It is like reading
a road map through a soda straw' Lauese
n, IEEE Software, April 98
Write a Comment
User Comments (0)
About PowerShow.com