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 trial

Android Build an Interactive Story App The Model-View-Presenter Pattern Adding Custom Constructors

Santiago Serrano
Santiago Serrano
2,754 Points

Shouldn't we have used the setFinalPage setter instead of changing the field directly in the constructor?

Aren't getters and setters precisely for this? If we had to change something or perform another action when we changed our field (isFinalPage) we would have to update both the constructor and the setter.

1 Answer

alastair cooper
alastair cooper
30,617 Points

The setter is a public function used for access from outside the class. As this will always be the final page, it is best to set it in the constructor when the object is instantiated so that any calls to the getter will return the desired result. A better question would be 'why did we create the setter in the first place?' as we don't ever want this value to change (unless I am jumping the gun here and we will indeed use it later in the course!)