Comparing Song Titles. Why not use getTitle()?
At about 14:20, when fixing the getSongsForArtist method to sort the songs alphabetically, why did we change the member variables to be protected instead of just using song1.getTitle()/song2.getTitle() ?
Craig DennisTreehouse Teacher
Honestly, for two reasons.
First, and not satisfying, I needed a way to introduce the
protected keyword. You don't use it often, but when you see it, I want you to know why it is used.
Secondly, getter methods can have other associated tasks in them, sometimes accessing the instance variable directly is preferred. Sometimes using a getter will cause a db hit and is in fact what you want to have happen. So it is contextual, but I wanted to show the concept, albeit blurry. :/ Sorry.
Hope that helps!