20-Jan-2003 - PowerPoint PPT Presentation

About This Presentation
Title:

20-Jan-2003

Description:

pick of the day. 20-Jan-2003. Lecture 7. Advanced Topics in Object Modeling: Demeter ... Law of Demeter. Within a method, messages can only be sent to. Its ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 14
Provided by: georgeh1
Learn more at: http://web.cs.wpi.edu
Category:
Tags: demeter | jan

less

Transcript and Presenter's Notes

Title: 20-Jan-2003


1
Advanced Topics in Object ModelingDemeter
  • 20-Jan-2003
  • Lecture 7

2
Outline
  • Previous Business
  • HW1 due tomorrow at 400 PM
  • Overlapping HTML links
  • TA Office hours in Fuller A22
  • Reading Questions
  • Lecture Contents

3
Reading Questions
  • TBA

4
Now ready for dynamism
  • Structured class diagrams are only so useful
  • How do objects from these classes communicate?
  • Static relationships ? dynamic relationships

1
1
Controller
updates
updates


Model
View
5
Object Communication
  • Message Metaphor
  • Object m sends a message to object n
  • Messages ? method calls/operations
  • synchronous invocation
  • blocks for return value
  • side effects to parameters discouraged

6
Object Sequence Diagram
cController
mModel
vView
request
alter model
update view
pull data
time
  • Messages as arrows
  • Rectangles as active
  • Objects must have reference to target
  • Messages to self typically omitted from diagram

7
Coupling
  • The physical interaction between two classes.
  • Too much coupling leads to
  • maintenance problems
  • lower reuse
  • less flexible code
  • Are there guidelines for interaction? Yes!

8
Law of Demeter
Dont Talk toStrangers
  • Within a method, messages can only be sent to
  • Its enclosing object
  • A parameter of the method
  • For pragmatic reasons includes global objects
  • Attributes of the enclosing object
  • Includes elements of a collection
  • An object returned by a method of the enclosing
    object
  • An object created within the method

9
Law of Demeter visualized
o Class1
O1 Object
i Item
globalObj
bBook
x
1
2
m (O1,O2)
O1.x ()
2a
3
4
5
Class1
items Item
5 any object created in m
myOp Book
10
Specific anti-example
  • public int m (Obj o)
  • return o.getRoot().getValue()
  • What if Obj decides to rename getRoot()? Or throw
    a new exception? Or change the return type? Or
    what if null suddenly becomes a valid return
    value?
  • Most common abuse of interaction

11
Object Sequence Diagram 2
cController
mModel
vView
request
1
1
Controller
Update model
updates
updates
update view


Model
View
time
  • Controller really in control
  • Model and View totally subservient
  • To Obey Demeter, Controller maintains modelView
    aggregation

12
Tuesday Assignments
  • Homework due tomorrow
  • design books will be accepted ONLY at the
    beginning of class
  • electronic submission of assignment must be
    received by 400 PM
  • any late assignments will be ungraded

13
References
  • Law of Demeter
Write a Comment
User Comments (0)
About PowerShow.com