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 trialZak Manz
1,390 PointsHi, 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
Livia Galeazzi
Java Web Development Techdegree Graduate 21,083 PointsIn 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
47,876 PointsAs he stated in the third step, 'Getting Started', it has to do with separation of concerns.
Anthony Albertorio
22,624 PointsAnthony Albertorio
22,624 PointsGreat answer!