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

edumorlom
edumorlom
4,073 Points

I don't understand why he has a Prompter, Hangman, and Game class.

I understand what he is doing up until now but I still haven't figured out why he was three different classes. Couldn't he make the game all in 2 classes? Game and Hangman? Why Prompter?

2 Answers

Hello

I think the onstructor went over the subject of [Separation Of Responsibilities] concept.

Technically, I could have done the whole thing in a single Main Class ...

But a good software design requires that a class does one and oly one thing ... (prompt for input ... io class), Hangman class (does core of the Hangman game without worrying how the input came about; and lastly, the main class ... this is the driver.

so later on, I decide to instead getting command via the key board, I want to allow the user to provide input by vice ... you just say the letter, and my "New" Prompter whill grab it.

In this case, I will main changes to Prompter class, without impacting Main or Hangman.

Hope this helps ... if this answers your question, please mar the question as answered.

Thanks

Sean Hayes
PLUS
Sean Hayes
Courses Plus Student 8,106 Points

Another way of looking at they way he split everything up has to deal with Object Oriented Programming or OOP. In this collection of videos he is writing the code for a Hangman game, but what if he went on to write another game which also needed a block of code exactly like the Prompter class? Instead of rewriting all of the code over again, he could just import the existing code.