[Cs3] Progress by chapter

Mikhail Nesterenko mikhail at cs.kent.edu
Fri Apr 10 15:19:45 EDT 2020


> I had some confusion with the third part of the lab due last
> Tuesday.  Specifically, since the state of a process was implemented
> as a reference to a dependent class object, how were we supposed to
> change the state without having to deallocate the actual object from
> memory?  Clone() doesn't seem like it can do a type conversion from
> within a concrete class.  Or were we supposed to do something else
> entirely?

The state of a process is implemented as a pointer to a particular
state class, for example New. Each state is implemented as
Singleton. Multiple processes may point to a single state. So, the
prototype process, let's call it "starter", has this setup

starter --> SingletonNewState


When you implement clone(), starter creates its own copy, pointing to
the new state For example this code:

newProcess = starter.clone()

Will result in

starter --> SingletonNewState
              ^
newProcess ---|


Thanks
--
Mikhail


More information about the cs3 mailing list