Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Ethan Morris18,666 Points
using public final instead of private final for characterName?
Now that we have learned about the final modifier is it not better to use it along with public for the characterName variable? e.g. "public final String characterName;"
This way the property can still be access with dispenser.characterName instead of having to create a getter method to return it. The final modifier achieves the intended purpose of making characterName private in an earlier video which was to stop it being updated once created.
Traian Butaru5,451 Points
I think you get the same thing, but you’re missing on benefits of the encapsulations. Maybe, at a later date, you would like to do some manipulations before returning the characterName. It’s easier just to modify the getter than creating an extra method and changIng all the code to work with your new method.