- provides a template that can be used to create many instances/objects with the same behavior and the same types
- Objects are instances of a class that have potentially a different state
Encapsulation is provided by classes, which are the fundamental building block of object oriented programming.
Classes
- serve as a blueprint for an object
- A class definition provides the function of the class
Type- what class was used to create the object
Name- an identifier for the object, can be used to distinguish between one another
Member Data- The state of the object
Member Functions- The behavior of the object
DDU- "Declare, Define, Use"
-
- Declarations specify an interface
- Define- Definitions specify implementation
- Use- Interacting with the interface to perform a function
An interface is a simplified view of a program, that allows for easier user input/output. It makes complicated tasks simpler. In other words the user should not need to understand the implementation.
We can declare member data (state) or member functions (behavior) as:
- Public - access from outside class
- Private - access from inside class (also known as "hidden")
- Protected - access from inside class, and from derived classes
The public members of a class provide the interface that the user can see.
Private member data protects the user from messing up the program, it limits there access.
Unchecked State is Bad
Types of Member Functions
- Accessors- functions that do not change state
- Mutators- are functions that do change
An example of the following are:
- Getters- accessors that just return the value of a private member data
- Setters- a mutator that sets member data