Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects Creating the MVP Prompting for Guesses

game object?

Instead of sending the game through the constructor, could we not have created a game object directly in the prompter class?

1 Answer

Dane Parchment
Dane Parchment
Treehouse Moderator 11,021 Points

You could, but it wouldn't make much organizational sense, the prompter's job is to prompt, not actually handle the game logic. In computer science we call this The Separation of Concerns Principle, and it is an extremely important principle. Basically your program should be split into distinctive parts and each part should simply be in charge of it's own thing, or concern. There are many reasons for this but the most important one is for maintenance as objects that do things outside of it's scope can become harder to debug and add/remove to.

In short The prompter is it's own thing, it is in charge of prompting the user, not for creating the game itself.

That makes sense, thanks for your reply.