UML Structural Diagrams: Object Diagrams and Class Diagrams Compared and Applied

UPI Study › Courses › System Analysis and Design › Free lessons › Lesson 4.8 Free with a free account

UML Structural Diagrams: Object Diagrams and Class Diagrams Compared and Applied

System Analysis and Design · Chapter 4: Requirements Validation, Modeling, and UMLSection 4.8 · lesson 31 of 698 min · free with a free account

← Designing with Objects: The OOAD ApproachNext lesson: The Design Phase Within the Software Development Life Cycle →

Earn 3 college credits for System Analysis and DesignRecommended for credit by NCCRS · Computer Science 390 · self-paced · one payment, lifetime access

In this lesson

Class boxes, visibility, multiplicity, whole-part relationships, and snapshots.

  • Read a class box's 3 compartments and its visibility symbols
  • Read an association and its multiplicity at each end
  • Distinguish aggregation from composition, and read generalization
  • Explain how an object diagram differs from a class diagram, and when to use each

Transcript

Everything said in the video, section by section (1,094 words). Read along, or search it.

Requirements Validation, Modeling, and UML

Class Diagrams and Object Diagrams

The class diagram is the most common structural diagram in U M L. It defines the blueprint for every object a system will create. Its close relative, the object diagram, shows one particular set of those objects, at a single moment. This section covers the notation both diagrams share, and the notation that sets them apart.

The Most Common Structural Diagram

Blueprint and Snapshot

Think of the difference like this. A class diagram is a blueprint. It says what every object of a type will look like. An object diagram is a snapshot. It shows actual objects, with actual values, at one moment in time. The notation is closely related, which is exactly why the two are easy to confuse. We will start with the class diagram, and come back to the snapshot at the end.

Figure 1

The Class Box and Visibility

A class is drawn as a rectangle, split into three compartments. The class name sits at the top. Its attributes sit in the middle. And its operations sit at the bottom. Each attribute and operation starts with a visibility symbol. That symbol controls which other classes can access it directly. A plus sign means public. Any other class can access it. A minus sign means private. Only the class itself can access it. A hash sign means protected. The class and its subclasses can access it. And a tilde means package. Only classes within the same package can access it. Recall encapsulation from the last section. The minus sign is how a class diagram shows it.

Figure 2 and 3

Associations and Whole-Part Relationships

Here are the relationships between classes. At the top, an association. A line connects customer and order, labeled with a verb. Places. The numbers at each end are the multiplicity. Read it from left to right. One customer places zero or more orders. At the bottom, two whole-part relationships, each marked with a diamond on the whole's side. On the left, a department and its employees, with a hollow diamond. That is aggregation. On the right, an order and its order lines, with a filled diamond. That is composition. The difference between hollow and filled matters a great deal, as we will see.

How Many?

Multiplicity

Let's look at multiplicity more closely. An association is a line connecting two classes that take part in a relationship, often labeled with a verb. Multiplicity, written at each end, states how many instances of one class can be associated with a single instance of the other. One means exactly one. Zero dot dot one means zero or one. Zero dot dot star, or just a star, means zero or more. One dot dot star means one or more. A single number, like three, means exactly three. And two dot dot five means between two and five, inclusive. Multiplicity turns a vague relationship into a precise rule, and precise rules can be tested.

Whole and Part

Aggregation vs. Composition

Aggregation and composition are both special forms of association. Both model a whole-part relationship. They differ in one important way. Can the part exist independently of the whole? In aggregation, drawn with a hollow diamond, it can. The part can exist on its own, and can even belong to a different whole later. An employee still exists if their department is eliminated. In composition, drawn with a filled diamond, it cannot. The part is created and destroyed along with the whole. An order line is deleted automatically when its order is deleted. A useful test is to ask, if I delete the whole, should the parts disappear too? If yes, it is composition.

Figure 4

Generalization: The Is-A Relationship

Generalization models an is-a relationship between two classes. The child class inherits the attributes and operations of the parent, and can add its own on top. It is drawn as a solid line, with a hollow triangle pointing at the parent. Here, the parent is vehicle, with a top speed. Car is a vehicle. It inherits top speed, and adds its own attribute, the number of doors. Truck is also a vehicle. It inherits top speed, and adds a bed length. Notice that the triangle always points at the more general class.

Figure 5

Object Diagrams as Snapshots

Now the snapshot. An object diagram uses the same rectangular notation as a class diagram, but it represents specific instances. Each box names one object, in the form object name, colon, class name, with the name underlined. And instead of attribute types, it lists that object's actual values. Here is the customer class. Its attributes are a customer I D, a name, and loyalty points, each with a type. And here is one object of that class, Maria. Her customer I D is C one zero four two. Her name is Maria Alvarez. And she has three hundred eighty loyalty points. Those values only hold true at one moment. That is why an object diagram is best understood as a snapshot, not a permanent blueprint.

Choosing

When to Use Each

So when do you use each? A class diagram shows the general structure every instance will follow. An object diagram shows the actual values of specific instances, at one moment. A class diagram is built during design, before any instances exist. An object diagram is built during analysis or debugging, once real data is available. A class diagram is best for communicating the overall data model to the team. An object diagram is best for verifying that a confusing association, or multiplicity rule, actually works with real data. And a class diagram stays accurate as long as the design is unchanged, while an object diagram is accurate only for the moment it was captured. Most projects use both together, rather than choosing one.

Key Terms

The Vocabulary of This Section

Let's lock in the key terms. Visibility is the access level of a member. Plus for public, minus for private, hash for protected, and tilde for package. An association connects two classes in a relationship, and multiplicity states how many instances link at each end. Aggregation is a whole-part relationship with a hollow diamond, where the part can outlive the whole. Composition uses a filled diamond, and the part cannot exist without the whole. Generalization is an is-a relationship, with a hollow triangle pointing at the parent. And an object diagram shows specific instances, and their real values, at one moment.

Key Takeaways

What to Carry Forward

To pull this together. A class box has three compartments, name, attributes, and operations, and each member's visibility symbol controls access. Multiplicity at each end of an association states how many instances can be linked on that side. Aggregation, with a hollow diamond, lets the part outlive the whole. Composition, with a filled diamond, does not. Generalization, drawn with a hollow triangle, models inheritance. And object diagrams show real values at one moment, verifying the design that class diagrams communicate.

About System Analysis and Design at UPI Study

System Analysis and Design (Computer Science 390) is a self-paced online course of 69 video lessons in 9 chapters, from the analyst's role and requirements to UML modeling, interface and database design, testing, maintenance and project management. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: Software Engineering vs Systems Analysis

Why take it here

Why students take System Analysis and Design with UPI Study

From business problem to working systemSystem Analysis and Design teaches how analysts study a business need and turn it into a system design: requirements, UML and data-flow models, interface and database design, implementation and project management. It is a core course in information systems and IT degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

System Analysis and Design carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About UML Structural Diagrams: Object Diagrams and Class Diagrams Compared and Applied

What do the visibility symbols mean in a UML class diagram?
Visibility symbols in a UML class diagram show which other classes can access an attribute or operation directly. A plus sign (+) means public, so any class can access it. A minus sign (-) means private, accessible only within the class itself. A hash sign (#) means protected, open to the class and its subclasses. A tilde (~) means package, open to classes in the same package.
What is the difference between aggregation and composition in UML?
Aggregation and composition are both whole-part relationships, but in aggregation the part can exist independently of the whole, while in composition it cannot. Aggregation uses a hollow diamond, as with a department and its employees, since an employee still exists if the department is eliminated. Composition uses a filled diamond, as with an order and its order lines, which are deleted along with the order.
How do you read multiplicity on a UML association?
Multiplicity, written at each end of an association, states how many instances of one class can be linked to a single instance of the other. The notation 1 means exactly one, 0..1 means zero or one, 0..* or * means zero or more, 1..* means one or more, and 2..5 means between two and five inclusive. So a customer-to-order association can state that one customer places zero or more orders.
What is the difference between a class diagram and an object diagram?
A class diagram is a blueprint showing the general structure every instance will follow, while an object diagram is a snapshot of specific instances and their actual values at one moment. Object boxes are named in the form objectName : ClassName, underlined, and list real values instead of attribute types. Class diagrams communicate the data model during design, while object diagrams help verify associations and multiplicity with real data.

About the System Analysis and Design course

How many college credits is System Analysis and Design?
System Analysis and Design (Computer Science 390) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does System Analysis and Design cost and what is included?
$250, paid once, with lifetime access: all 69 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does System Analysis and Design take?
It is self-paced with no deadlines. The 69 lessons total about 9 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in System Analysis and Design.

69 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

System Analysis and Design
3 credits · NCCRS
Enroll →