vendredi 3 juillet 2020

Correct State pattern implementation

Help me figure out the State pattern. There is a task - to write a program that simulates turning on and off the PC. I was prompted to use the State pattern. But I'm not sure that I use it correctly. My turn pc model has things in common with a real one, but certainly not for sure. Therefore, I divided the boot process into several stages - turning on the computer, boot loaders 1-3 level and loading the kernel os. Program structure.

At each stage, their actions are performed, in addition to implementing the methods of the implemented interface. In the implementation of the interface methods, I assign a new object to the state of the pc. I do this because I saw a similar action in the example. But I don’t understand how to use it later. Interface and an example implementation of the method in one of the stages.

In the main method, I call the instance constructor of each stage and put the result in a list. And if at the end all the stages worked without errors - the PC is started and ready for use. Main.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire