Welcome to the Treehouse Community
Looking to learn something new?
Zak Manz1,390 Points
Hi, Could someone please explain why Prompter, Game and Hangman.java are in three separate files not all in one
Sorry I know its a silly question, please explain why Prompter, Game and Hangman.java are in three separate files not all in one.Please explain what each file is for. Thank you.
In theory you could put them all in a single file. But it would get confusing, because all these classes have different jobs to do.
Here there are only 3 classes, but in a real applications, you might have hundreds or even thousands of classes. If all those thousands of classes were in a single file, knowing which bit of code does what would be very difficult, because it would be one huge file. Structure is important in order to create code that is easy to understand and maintain. That's why we use the single responsibility principle: a class should only have one job. If it does two jobs, it should become two classes.
There are other reasons as well, but you'll understand them once you've spent more time learning java. For example testing is easier with well structured code. Happy coding!
Rick Gleitz45,177 Points
As he stated in the third step, 'Getting Started', it has to do with separation of concerns.