Law of Demeter Principle - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Law of Demeter Principle

Description:

8/16/09. UBS/LoD. 1. Law of Demeter Principle ... this application of the Law of Demeter Principle to OO: example follows in a few s. ... – PowerPoint PPT presentation

Number of Views:99
Avg rating:3.0/5.0
Slides: 8
Provided by: karl134
Category:
Tags: demeter | law | principle

less

Transcript and Presenter's Notes

Title: Law of Demeter Principle


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

2
Law of Demeter
FRIENDS
3
closely related
4
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.

5
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()

6
Violations Dataflow Diagram
m
foo()
2c
1b
B
C
A
4q()
bar()
3p()
P
Q
7
OO Following of LoD
m
foo2
foo()
c
1b
B
C
A
2foo2()
4bar2()
bar2
bar()
3p()
q()
P
Q
Write a Comment
User Comments (0)
About PowerShow.com