Implementing classes so that they adhere to the principle of encapsulation is quite simple. To achieve this goal, there are just two basic rules:
-
Don't use any public properties.
-
Don't reference objects outside the class unless the reference was passed to the class as a parameter.