Presentation is loading. Please wait.

Presentation is loading. Please wait.

Preliminaries Stage 1 due tonight by 9:00 PM HW1 discussion (4PM, Commons 9) –may try for next week? HW2 available later today, due Monday by 9:00 PM.

Similar presentations


Presentation on theme: "Preliminaries Stage 1 due tonight by 9:00 PM HW1 discussion (4PM, Commons 9) –may try for next week? HW2 available later today, due Monday by 9:00 PM."— Presentation transcript:

1

2

3 Preliminaries Stage 1 due tonight by 9:00 PM HW1 discussion (4PM, Commons 9) –may try for next week? HW2 available later today, due Monday by 9:00 PM

4 LRStruct design

5 Empty vs. NonEmpty state (look Ma, no NullPointerException!) An LRS object delegates all calls to its LRS State object – which can respond to all messages. Empty and NonEmpty states respond differently. There is never a null pointer in the structure! (Think about the implications of this for a while.)

6 What is basic (invariant) list functionality? insert new item at front remove item from front set/get first item (head) set/get rest (tail) plus (in Java) methods inherited from Object (toString, equals, etc)

7 How are these methods defined? public LRStruct insertFront(E item) { return _state.insertFront(this, item); } public E removeFront() { return _state.removeFront(this); } public LRStruct setDatum(E item) { return _state.setDatum(this, item); } public E getDatum() { return _state.getDatum(this); } public LRStruct setRest(LRStruct rest) { return _state.setRest(this, rest); } public LRStruct getRest() { return _state.getRest(this); }

8 LRStruct delegates to State! All of these methods delegate to the state of the LRStruct. States polymorphically determine what happens.

9 Polymorphism In class discussion: –Objects behave according to their definitions –Variable of some type can refer to object of any subtype


Download ppt "Preliminaries Stage 1 due tonight by 9:00 PM HW1 discussion (4PM, Commons 9) –may try for next week? HW2 available later today, due Monday by 9:00 PM."

Similar presentations


Ads by Google