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 Current Progress

Zak Manz
Zak Manz
1,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.

2 Answers

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 Gleitz
Rick Gleitz
45,177 Points

As he stated in the third step, 'Getting Started', it has to do with separation of concerns.