Objects

An object is a model element that represents an instance of a class. While a class represents an abstraction of a concept or thing, an object represents an actual entity. An object has a well-defined boundary and is meaningful in the application. Objects have three characteristics: state, behavior, and identity. State is a condition in which the object may exist, and it usually changes over time. The state is implemented with a set of attributes. Behavior determines how an object responds to requests from other objects. Behavior is implemented by a set of operations. Identity makes every object unique. The unique identity lets you differentiate between multiple instances of a class if each has the same state.

The behaviors of objects can be modeled in sequence and activity diagrams. In sequence diagrams, you can display how instances of different classes interact with each other to accomplish a task. In activity diagrams, you can show how one or more instances of an object changes states during an activity. For example, an e-commerce application may include a "Cart" class. An instance of this class that is created for a customer visit, such as "cart100:Cart." In a sequence diagram, you can illustrate the stimuli, such as "addItem( )," that the "cart100:Cart" object exchanges with other objects. In an activity diagram, you can illustrate the states of the "cart100:Cart" object, such as empty or full, during an activity such as a user browsing the online catalog.

Shape

In sequence and activity diagrams, an object appears as a rectangle with its name underlined. In sequence diagrams, a lifeline (a dashed, vertical line) is attached to the bottom of an object to represent the existence of the object over a period of time. For details about lifelines, see Lifelines.

Object Object with Lifeline

Types of Objects

The following table identifies three types of objects.

Types of Objects Description
Active Owns a thread of control and may initiate control activity. Processes and tasks are kinds of active objects.
Passive Holds data, but does not initiate control.
Multiobject Is a collections of object or multiple instances of the same class. It is commonly used to show that a set of objects interacts with a single stimulus.

Using Objects

Objects can appear in a sequence diagram to represent concrete and prototypical instances. A concrete instance represents an actual person or thing in the real world. For example, a concrete instances of a "Customer" class would represent an actual customer. A prototypical instance represents an example person or thing. For example, a prototypical instance of a "Customer" class would contain the data that a typical customer would provide.

Naming Conventions

Each object must have a unique name. A full object name includes an object name, role name, and class name. You may use any combination of these three parts of the object name. The following table identifies the variations of object names.

Syntax Example Description
object/role:class cart100/storage:cart Named instance (cart100) of the cart class that is playing the storage role during an interaction.
object:class cart100:cart Named instance (cart100) of the cart class.
/role:class /storage:cart Anonymous instance of the cart class playing the storage role in an interaction.
object/role cart/storage An object named cart playing the storage role. This object is either an object that is hiding the name of the class or an instance that is not associated with a class.
object cart100 An object named cart100. This object is either an instance that is hiding the name of the class or an instance that is not associated with a class.
/role /storage An anonymous instance playing the storage role. This object is either an instance that is hiding the name of the object and class or an instance that is not associated with an object or class.
:class :cart Anonymous instance of the customer class.

Related Topics

UML Sequence Diagrams | Stimuli