Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Access Modifiers 6:04
- Access 3 questions
- Associative Arrays 7:36
- Cleaning Up the Class 2:58
- Accessing Arrays 5 objectives
- Adding Getters and Setters 8:32
- Ready Get Set Go 5 questions
- Static Methods 4:52
- Recipe Details 3:16
- Separating Methods 2:43
- Static 4 objectives
- Magic Methods 5:05
- Magic Constants 6:14
- All About the Magic 5 questions
- Populating the Recipes 3:15
- Controlling the Class 3 objectives

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
What about the Getters and Setters for the rest of the properties? Do you have to add Getters and Setters for ALL of them? What if you don’t care about doing anything with the property before it gets set. Can we just leave those public?
Documentation
Why Getters and Setters
Some of these are concepts we wont be covering in this course, but here are a few ides:
- Controlling the of behavior associated with getting or setting the property - this allows additional functionality (like validation) to be added more easily later.
- Hiding the internal representation of the property while exposing a property using an alternative representation.
- Allowing the getter/setter to be passed around as lambda expressions rather than values.
- Getters and setters can allow different access levels - for example the get may be public, but the set could be protected.
- Insulating your public interface from change - allowing the public interface to remain constant while the implementation changes without affecting existing consumers.
- Providing a debugging interception point for when a property changes at runtime.
- Improved interoperability with libraries that are designed to operate against property getter/setters - Mocking, Serialization, etc.
- Allowing inheritors to change the semantics of how the property behaves and is exposed by overriding the getter/setter methods.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
annapoff
13,552 Points2 Answers
-
Mohammed Jammeh
37,463 Points1 Answer
-
Petrov von Petrov
21,916 Points1 Answer
-
thimoschroeder
23,470 Points6 Answers
-
ammarkhan
Front End Web Development Techdegree Student 21,661 Points1 Answer
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up