After learning about encapsulation in OOP, I started to use only protected
and private
properties, share data via accessors and change properties via mutators.
Right now, I’m afraid of declaring public
properties.
Is it good to keep everything private
and protected
or is there some cases where I need to use public
properties?
If you don’t need control over a data/property you are exposing, you can use public property with no problem.
For all other cases (like if it’s a property with only in-class use or if you want to expose a property on which you want to keep read/write control), it’s better to keep them private and some time protected if you plan for your class to be inherited
4