The object-oriented model is based on a collection of objects, like the E-R
model.
- An object contains values stored in instance variables within
the object.
- Unlike the record-oriented models, these values are themselves objects.
- Thus objects contain objects to an arbitrarily deep level of nesting.
- An object also contains bodies of code that operate on the the object.
- These bodies of code are called methods.
- Objects that contain the same types of values and the same methods
are grouped into classes.
- A class may be viewed as a type definition for objects.
- Analogy: the programming language concept of an abstract data type.
- The only way in which one object can access the data of another object
is by invoking the method of that other object.
- This is called sending a message to the object.
- Internal parts of the object, the instance variables and method code,
are not visible externally.
- Result is two levels of data abstraction.
For example, consider an object representing a bank account.
- The object contains instance variables number and balance.
- The object contains a method pay-interest which adds interest
to the balance.
- Under most data models, changing the interest rate entails changing
code in application programs.
- In the object-oriented model, this only entails a change within the
pay-interest method.