[Cs3] CSIII Questions
Mikhail Nesterenko
mikhail at cs.kent.edu
Mon Nov 8 11:33:58 EST 2021
> Through the course of going over my notes (and your lectures again) I came
> across some gaps in my knowledge. Please fill them to the best of your
> ability.
>
> 1) I feel like I am missing an important implementation for the prototype
> design pattern.
> As far as I can tell, the entire design pattern consists of a pair of
> methods. A virtual one in the base class, and an overriding one in the
> derived class. Am I overlooking something?
client accesses the abstract prototype while concrete proptotype(s)
supply the overloaded clone() function that returns an object in the
state of the concrete prototype.
>
> 2) During the state design pattern lecture you touched on why the
> singleton was used for the hungry and full states in zork.cpp. I do
> not fully understand how using a singleton is possible. Is the
> instance like a location? Do the characters just go there, and
> leave?
The context (the prototype that delegates behavior to the state) has a
pointer to one of the concrete states. The specific concrete states
determines what behaviors the Context actually does. One of those
behaviors may be transitioning to another concrete state. In which case
the state moves the pointer of the context to anther state.
The reason the concrete states are singletons is that context pointing
to the particular concrete state already signifies what state (and
behaviors) the context has. Therefore, there does not need to be
multiple instances of a concrete state: multiple contexts may point to
the same concrete state.
This may sound like a lot of words. I suggest carefully going through
the Zork example we studied in class.
Thanks,
--
Mikhail
More information about the cs3
mailing list