1/14
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What are behavioural design patterns concerned with?
Algorithms and the assignment of responsibilities between objects.
What are the two types of behavioural patterns listed in the slides?
Class behavioural and object behavioural.
What pattern is the main focus of this deck?
State.
What is the definition of the State pattern?
Allow an object to alter its behaviour when its internal state changes; the object will appear to change its class.
What is the main problem in the naive LineOfCredit design?
Big if/switch statements based on the current state.
What states does the LineOfCredit example use?
New, Applied, Open, Cancelled.
What operations does the LineOfCredit example include?
apply, approve, withdraw, makePayment, cancel.
What replaces the enum in the State pattern version?
A pointer/reference to a state object.
What does the context object do in the State pattern?
It delegates requests to the current state object.
What does the base LineOfCreditState class provide?
Virtual operations for all possible actions, often with default invalid-state behavior.
What happens in AppliedState::approve()?
The state changes to OpenState.
What happens in AppliedState::cancel()?
The state changes to CancelledState.
What does OpenState::withdraw() do?
It checks available credit and increases balance owing if allowed.
What is one consequence of the State pattern?
It localizes state-specific behavior.
What is another consequence of the State pattern?
It makes state transitions explicit.