public
: it will be expose to the outside.protected
: only when you are using inheritance, and you want to have them accesible from the child classes.private
: it should not be expose to the outside. To encapsulate code within its minimum scope.
Keep to the minimum the scope of your methods and properties.
Reduce the scope visibility to the minimum using the final
keyword.
When you see a class prefix with the final keyword you will be sure that this class is not extended by any other in the code, which makes it more readable.
You can read more about final classes in its own page
Writing protected
when there is no inheritance at all.
Do not leave
public
orprotected
something unless you know that you will have to expose it to the outside.