Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,835 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!