What Is An Object Diagram in UML?: Similarities To The Class Diagram
What Is An Object Diagram in UML?: Similarities To The Class Diagram
A UML object diagram represents a specific instance of a class diagram at a certain moment in
time. When represented visually, you'll see many similarities to the class diagram.
An object diagram focuses on the attributes of a set of objects and how those objects relate to
each other. For instance, in this object diagram below, all three bank accounts tie back to the
bank itself. The class titles show the type of accounts (savings, checking, and credit card) that a
given customer could have with this particular bank. The class attributes are different for each
account type. For example, the credit card object has a credit limit, while the savings and
checking accounts have interest rates.
Object diagrams are not limited to banking use cases, however, as you can easily make an object
diagram for family trees, corporate departments, or any other system with interrelated parts.
Object diagrams are simple to create: they're made from objects, represented by rectangles,
linked together with lines. Take a look at the major elements of an object diagram.
Objects
Objects are instances of a class. For example, if "car" is a class, a 2007 Nissan Altima is an
object of a class.
Class titles
Class titles are the specific attributes of a given class. In the family tree object diagram, class
titles include the name, gender, and age of the family members. You can list class titles as items
on the object or even in the properties of the object itself (such as color).
Class attributes
Class attributes are represented by a rectangle with two tabs that indicates a software element.
Links
Links are the lines that connect two shapes of an object diagram to each other. The corporate
object diagram below shows how departments are connected in the traditional organizational
chart style.
A developer will find object diagrams useful in many instances. These include:
UML specifications typically don't change when you describe an object diagram in different
programming languages. The whole purpose of UML is for developers to plan out software
independent of specific platforms. Below are two of the most commonly used types of object
diagrams in different programming languages.
Objective C has become very popular since Apple's release of "Objective C 2.0," and now it's the
programming language of choice for Apple marketplace applications. Most people who use
Objective C object diagrams are attempting to show instances for an iPhone app.
There are object diagrams that can be used in UML to describe instances that would ultimately
be programmed in Java, and there are diagrams that describe Java objects that have nothing to do
with UML.
The Unified Modeling Language (UML) can help you model systems in various ways. One of
the more popular types in UML is the class diagram. Popular among software engineers to
document software architecture, class diagrams are a type of structure diagram because they
describe what must be present in the system being modeled. No matter your level of familiarity
with UML or class diagrams, our UML software is designed to be simple and easy to use.
The class shape itself consists of a rectangle with three rows. The top row contains the name of
the class, the middle row contains the attributes of the class, and the bottom section expresses the
methods or operations that the class may use. Classes and subclasses are grouped together to
show the static relationship between each object.
Class diagrams offer a number of benefits for any organization. Use UML class diagrams to:
Illustrate data models for information systems, no matter how simple or complex.
Better understand the general overview of the schematics of an application.
Visually express any specific needs of a system and disseminate that information
throughout the business.
Create detailed charts that highlight any specific code needed to be programmed and
implemented to the described structure.
Provide an implementation-independent description of types used in a system that are
later passed between its components.
Basic components of a class diagram
Upper section: Contains the name of the class. This section is always required, whether
you are talking about the classifier or an object.
Middle section: Contains the attributes of the class. Use this section to describe the
qualities of the class. This is only required when describing a specific instance of a class.
Bottom section: Includes class operations (methods). Displayed in list format, each
operation takes up its own line. The operations describe how a class interacts with data.
All classes have different access levels depending on the access modifier (visibility). Here are
the access levels with their corresponding symbols:
Public (+)
Private (-)
Protected (#)
Package (~)
Derived (/)
Static (underlined)
Member scopes
Classifiers are static members while instances are the specific instances of the class. If you are
familiar with basic OO theory, this isn't anything groundbreaking.
Depending on the context, classes in a class diagram can represent the main objects, interactions
in the application, or classes to be programmed. To answer the question "What is a class diagram
in UML?" you should first understand its basic makeup.
Interactions
The term "interactions" refers to the various relationships and links that can exist in class and
object diagrams. Some of the most common interactions include:
In this example, the object "Car" would inherit all of the attributes (speed, numbers of
passengers, fuel) and methods (go(), stop(), changeDirection()) of the parent class ("Vehicle") in
addition to the specific attributes (model type, number of doors, auto maker) and methods of its
own class (Radio(), windshieldWiper(), ac/heat()). Inheritance is shown in a class diagram by
using a solid line with a closed, hollow arrow.
Bidirectional association: The default relationship between two classes. Both classes are
aware of each other and their relationship with the other. This association is represented
by a straight line between two classes.
In the example above, the Car class and RoadTrip class are interrelated. At one end of the line,
the Car takes on the association of "assignedCar" with the multiplicity value of 0..1, so when the
instance of RoadTrip exists, it can either have one instance of Car associated with it or no Cars
associated with it. In this case, a separate Caravan class with a multiplicity value of 0..* is
needed to demonstrate that a RoadTrip could have multiple instances of Cars associated with it.
Since one Car instance could have multiple "getRoadTrip" associations—in other words, one car
could go on multiple road trips—the multiplicity value is set to 0..*
As an example, on your road trip through Arizona, you might run across a speed trap where a
speed cam records your driving activity, but you won't know about it until you get a notification
in the mail. It isn't drawn in the image, but in this case, the multiplicity value would be 0..*
depending on how many times you drive by the speed cam.
Creating a class diagram to map out process flows is easy. Consider the two examples below as
you build your own class diagrams in UML.
A class diagram can show the relationships between each object in a hotel management system,
including guest information, staff responsibilities, and room occupancy. The example
below provides a useful overview of the hotel management system. Get started on a class
diagram by clicking the template below.
Class diagram for an ATM system
ATMs are deceptively simple: although customers only need to press a few buttons to receive
cash, there are many layers of security that a safe and effective ATM must pass through to
prevent fraud and provide value for banking customers. The various human and inanimate parts
of an ATM system are illustrated by this easy-to-read diagram—every class has its title, and the
attributes are listed beneath. You can edit, save, and share this chart by opening the document
and signing up for a free Lucidchart account.