Information Hiding#
The process of hiding the ‘inner workings’ of a method or class by providing only an interface to access the object.
Encapsulation#
The binding of data and methods into a single unit, i.e. a class.
It is considered good convention to declare all variables in a class as private if the class designed for encapsulation
.
Access is granted through getters
and setters
.
Get and Set#
Get
allows the reading of a property’s value, while set
allows the modifying of a property’s value.
It’s common practice to write get
and set
methods using the property name. For example for __username
we would use getUsername
and setUserName
.