User Defined Types  «Prev  Next»
Lesson 5 Objects are instances of classes
Objective Describe how Objects instantiate Classes

Describe how Objects instantiate Classes

A class defines a type. In general, there can be many different instances of the class, each of which may have different values for the attributes of the class. These instances are called objects. For example, the origin is a Point object whose x attribute is 0.0 and whose y attribute is 0.0. This can be represented by an object diagram.
Object diagrams are useful when giving examples of values for all the attributes or showing how an object changes as the system runs. An object diagram is deliberately similar to a class diagram. It is divided into two compartments, like this:

Origin Point
  1. An object diagram is deliberately similar to a class diagram. It is divided into two compartments. The top compartment holds the name of the object, followed by a colon and the name of the class. Both the name of object and the name of the class are underlined.
  2. The next compartment holds the names of object's attributes and their values, here 0.0 and 0.0. The type is omitted though it is often implicit in the values.

Object Diagram Example
Occasionally, you will see diagrams for anonymous objects. These are objects for which no name is obvious or needed.
In the video store course example, objects of the Title class might include the Gone With the Wind title or the Bambi title. Objects of the Customer class might include "Jo Smith" Here's how that object might look:
Jo Smith: Customer
Name: Jo W. Smith
Address: 123 Main Street, Ourtown
Phone: 555-1212
Balance: 1.00