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
25,418 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!)