Objects
A class represents an abstraction of a concept or of a physical thing, whereas an object represents a concrete entity. An object has a well-defined boundary and is meaningful in the application. Objects have the characteristics that are listed in the following table:
Characteristic | Description |
---|---|
State | The state is the condition in which an object can exist. An object’s state is implemented with a set of attributes and usually changes over time. |
Behavior | Behavior determines how an object responds to requests from other objects. Behavior is implemented by a set of operations. |
Identity | The identity of an object makes it unique. You can use the unique identity of an object to differentiate between multiple instances of a class if each instance has the same state. |
Each object must have a unique name. A complete object name has three parts: object name, role name, and class name. You can use any combination of the parts when you name an object. The following table shows several object name variations for an online shopping system.
Syntax | Example | Description |
---|---|---|
object/role:class | cart100/storage:cart | A named instance (cart100) of the cart class performs the role of storage during an interaction. |
object:class | cart100:cart | A named instance (cart100) of the cart class |
/role:class | /storage:cart | Anonymous instance of the cart class that performs the role of storage in an interaction. |
object/role | cart/storage | An object named cart that plays the storage role. This object is either an object that hides 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 hides the name of the class or an instance that is not associated with a class. |
/role | /storage | An anonymous instance performs the role of storage. This object is either an instance that hides 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. |
Types of objects
The following table lists the three types of object.
Types of objects | Description |
---|---|
Active | A active object owns a thread of control and can initiate control activity. Processes and tasks are types of active objects. |
Passive | A passive object holds data, but does not initiate control. |
Multiple instance | Is a collection of objects or multiple instances of the same class. Multiple instances are commonly used to show that a set of objects interacts with a single message (or stimulus). |