startNewRound / updateLabels

There are many paths from here to there. You chose one of them.

In at least two (3?) places in Tutorial 1, you call startNewRound() followed by a call to updateLabels(). The path I followed was to put the call to updateLabels() right in the updateLabels() func. If the parameter list to updateLabels ever changes, I only have to make an update in one place.

Is there a specific reason you chose to call one after the other in multiple places? Given your greater experience in coding, is there something you’re thinking about that will make code changes easier if they come up? Did you follow a design pattern that, in the long run, is better in most cases?

Thanks in advance. Your responsiveness in this forum is stellar.

Well, sometimes I leave these things unsaid in the tutorials so people like yourself can figure out these things on your own. :smiley: So, well done! :thumbsup:

However, there is a reason for keeping them split up. One method changes the data model of the app, the other method updates the UI. In a well-architected app you usually want to keep those two things separate.

For a simple game like Bull’s Eye it doesn’t really matter, to be honest. However, when apps get bigger it becomes more important to separate data model and UI updates. This is the big idea behind the MVC (and MVVM) patterns. You’ll learn more about that in the next tutorials in the series.

Great answer, thanks. I appreciate the distinction between data and UI, so I’m right with you.

I think I’ll implement it as…

func updateDataAndUI() {
updateDataModel()
updateUI()
}

and call updateDataAndUI from multiple locations in the code.

Looks good to me. :slight_smile: