The Department of Computer Science & Engineering |
STUART C. SHAPIRO: CSE
115 C
|
See /projects/CSE115/Classlibs/Demos/PatternsLecture/
Can the same input result in different behavior at different times?
MEMORY = STATE
Same input can have different behavior if the state of the program is
different.
How to store, and use state information?
We will look at three patterns for the design of
programs that change their state as a result of input.
See
/projects/CSE115/Classlibs/Demos/PatternsLecture/Holder/
and /projects/CSE115/Classlibs/Demos/PatternsLecture/Proxy/
Note on translate
(from MovingEllipse
).
Destructive change, rather than creation of new point.
bsh % p1 = new java.awt.Point(10, 20); bsh % p2 = new java.awt.Point(15, 30); bsh % p3 = p1; bsh % print(p1 + " " + p2 + " " + p3); java.awt.Point[x=10,y=20] java.awt.Point[x=15,y=30] java.awt.Point[x=10,y=20] bsh % print(p1==p2); false bsh % print(p1==p3); true bsh % p1.translate(5, 10); bsh % print(p1 + " " + p2 + " " + p3); java.awt.Point[x=15,y=30] java.awt.Point[x=15,y=30] java.awt.Point[x=15,y=30] bsh % print(p1==p2); false bsh % print(p1==p3); true