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 trialEvgeniia Vakarina
3,317 PointsgetTitle() vs protected
Why is it better to make song's mTitle protected instead of just using getTitle() method?
1 Answer
Wout Ceulemans
17,603 PointsI think Craig made the fields protected to either (or both):
- Show that there is a protected access modifier and show a potential use case
- Personal code style
There is no real performance difference between using a field directly (like Craig did in the video) or using a getter. In the end, it comes down to personal choice. In general, getters are recommended by convention over direct field access (encapsulation). However, I think this is one of these special cases where you could use either.