A class defines a set of properties and suitable operations. From a type-safe programming language point of view, a class is a structure to implement a user-defined type, such as our User class in the preceding example.
Preferably, a class should be an implementation of an Abstract Data Type (ADT) that hides the implementation details.
An implementation of an ADT as a class can be composed of two kinds of method:
- Methods that return meaningful abstractions about the state of an instance
- Transformational methods to move from a valid instance state to another valid state
To be able to hide implementation details and for the sake of abstraction, all the data within a class should be private to the class.
Let's improve the abstraction ...