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 trialDylan Carter
4,780 PointsWhy aren't we putting the executing file in the package?
Can someone explain to me why every time we start a new project we keep the executing file(class) separate from the other constructing and defining ones(song, songbook)? what is the reason for keeping it out of there?
1 Answer
Lucas Santos
19,315 PointsMVC (Model, View, Controller)
It's a way of building applications that are easier to maintain by separating things into "Models" like song, songbook. Theres a lot to MVC, so much that I cannot just explain it to you in one answer. There are TONS of great tutorials and explanations on MVC out on the web, heres a great one
Dylan Carter
4,780 PointsDylan Carter
4,780 Pointsthanks. So KaraokeMachine.java would be the controller in this case?
Lucas Santos
19,315 PointsLucas Santos
19,315 PointsExactly, then the View would be the actual visuals to the app.
Dylan Carter
4,780 PointsDylan Carter
4,780 PointsI understand the concept of keeping the different "elements" of the program separate, but not really why they couldn't all just be separate classes in the same package.
Lucas Santos
19,315 PointsLucas Santos
19,315 PointsIt probably could all be in one package but can you imagine if you had a complex application with thousands of lines of code and many files to go though. It would be so sloppy and difficult to manage that you would waste a lot more of time then you should have. Remember this isn't just a "Java" concept this is a programming concept in general. I use this pattern with other programming languages as well.
Dylan Carter
4,780 PointsDylan Carter
4,780 PointsSo can an application have more than one package? I really don't understand the point you are trying to make about the big application, if it was a necessary part of the application, like this file that executes in this program, wouldn't you still want that in the package? I understand the concept of MVC but don't understand the point of separating the package, can you please explain a little more if you don't mind?