Java Java Objects Creating the MVP Remaining Tries

Korsons Don
Korsons Don
3,141 Points

Question about Separation of Concerns

The overall distribution of methods and properties among all three classes in the game application doesn't seem very intuitive to me. For example, why does the getCurrentProgress() method live in the Game class while the displayCurrentProgress() method live in the Prompter class? Any insights on this? Thanks!

1 Answer

saykin
saykin
9,820 Points

This a tough one, but I'll try and take a crack at it.

You want a class called Game to only deal with the game part of the program. Track progress, allowed misses, the answer etc. This is done so that if you ever decide to change up the interface of the program (Prompter) it doesn't affect the game. You can still use the same logic, but with a different interface. If you put displayCurrentProgress() in the Game class, you would have to change up the Game class every time you do a change the output or interface of the program.

More easily explained, you want each class to deal with only one thing. The Prompter class deals with input/output and the Game class deals with game logic. That way, changing one class doesn't affect the other.

Think of it as a car, say you have a flat tire (Prompter class), would you want to tinker with your engine (Game class) every time you change a tire? With separation of concern, you can change the tires without it affecting the engine and you can change the engine without it affecting the tires.

If you're still unclear on why this is done, please ask to clarify more. In the meantime, I will think more about how to better answer this question.

Korsons Don
Korsons Don
3,141 Points

It's beginning to make sense now. The method in the displayProgress() method in the prompter doesn't really handle any game logic, it merely uses the methods already defined in the game class. Thanks!