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 trialSarabeth Zogg
9,418 PointsGuiding principles for program flow through separate classes?
Is it somewhat arbitrary in which class you code certain functionality? For example, displaying the current progress after a guess in hangman seems to make as much sense from hangman.java as writing a method to do this in the prompter class and then calling it from hangman.java...Is there a certain logic to guide program flow through various objects/classes?
1 Answer
Alex Dewey
5,944 PointsIt's not explained to clearly in these examples but Craig does refer to the Seperation of Concerns earlier on. The aim is to have each class only responsible for one job or task. In this case, for example, the Game.java handles the game logic.
It's also common practice to follow a design architecture such as Model - View - Controller. This design pattern separates the Model (in this case the Game.jave or game logic) from the View (Hangman.java which is calling our methods to print to the console) and the Controller (Promter.java which takes the input from the user)
For your question showing progress would fall under the View section of the MVC architecture which we are using Hangman.java for.
I'm sure they go into a lot more detail on this later but mentioned earlier that this was so you can reuse code and adapt to other platforms easily without re-writing everything.
Christopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsChristopher Mlalazi
Front End Web Development Techdegree Graduate 17,305 PointsGood question I am also curious about this.