Best Practice Question: Should You Have Getters and Setters for Private Properties in a Component?
Let's say you have a component with a private property (a dependency) which will be injected into the component when it is instantiated. Now, when you're working inside the component, is it considered best-practice to have getters and setters for private properties even when they will never be exposed outside of the component?
I've seen some examples online in other languages (e.g. C#) where dependencies are injected and then referenced without relying on getters/setters. I haven't really been able to find a consensus on the optimal way to proceed when it comes to private properties.
Here's an example of a simple component that has a dependency (dependencyExample) which exists as a private property.
In this first example, I've used getters and setters which set the property when the component is instantiated (setDependencyExample()). Then, when a method (doSomething()) needs to utilize the property, the getter (getDependencyExample()) gets triggered in order to gain access to it.
https://paste.ofcode.org/ubhMPgSZR3rvExxES6yLHB
Now here's a second example where the private property does not have any getters/setters. Instead, the property is set and accessed directly via the variables scope:
https://paste.ofcode.org/JjbUWc6PBMez42i8UVgHn5
It seems to me that if you don't use getters/setters for private properties, you wind up with potentially much leaner code (if you have a lot of private properties). However, I'm not sure if this way of doing things violates some best-practice rule of OOP. I would love to hear your thoughts on the matter.
