Lesson 3 | Object diagram notation |
Objective | Compare and contrast the object diagram and the class diagram notation. |
objectName:ClassName
. The objectName
is
optional.
Person
class named John
might be
shown as:
John:Person age = 30 address = "123 Elm Street"
name: String
).getName(): String
).+
), private (-
), or protected (#
) access levels.Person
class might be shown as:+------------------------+ | Person | +------------------------+ | -name: String | | -age: int | +------------------------+ | +getName(): String | | +setAge(age: int): void | +---------------------+
Feature | Object Diagram | Class Diagram |
---|---|---|
Focus | Runtime instances and their states. | Static structure of the system. |
Abstraction Level | Instance-level (concrete). | Class-level (abstract). |
Relationships | Links between objects. | Associations, inheritance, composition, etc. |
Purpose | Shows real-time scenarios. | Provides a design blueprint. |
Elements | Objects and their values. | Classes, attributes, and methods. |
employeeid: integer = 0
first_name: char = blank
last_name: char = blank
streetline1: char = blank
streetline2: char = blank
city: char = blank
statecode: char = blank
zipcode: numeric = 0
addresstype: char = blank
setEmployeeID()
getEmployeeID()
setFirstName()
getFirstName()
setLastName()
getLastName()
setAddress()
getAddress()
setStreetLine1()
setStreetLine2()
setCity()
setStateCode()
setZipCode()
getStreetLine1()
getStreetLine2()
getCity()
getStateCode()
getZipCode()
Class diagram | Object diagram |
The class has three compartments: name, attribute, and operation. | The object has only two compartments: name and attribute. |
The class name stands alone in the class name compartment. | The format for an object name is object name, colon, class name (Tom : Employee ).
You will encounter this notation in other diagrams that model objects rather than classes. Sometimes the object name is left off and only the colon and class name are used. This is referred to as an anonymous object. |
The class attribute compartment defines the properties of the attributes. | The object defines only the current value of each attribute. |
Operations are listed in the class. | Operations are not included in the object because they would be identical for every object of the same class. |
The classes are connected with an association with a name and multiplicity. | The objects are connected with a link that has a name and no multiplicity. Classes represent a "classification" of objects, so it is necessary to specify how many mayparticipate in the association. Objects represent single entities. All links are one to one, so multiplicity is irrelevant. Roles may be used on links and associations. |