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
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of System Analysis and Design.
Lesson complete
Earn the 3 college credits for System Analysis and Design
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: The Design Phase Within the Software Development Life Cycle →← Designing with Objects: The OOAD ApproachNext lesson: The Design Phase Within the Software Development Life Cycle →
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.
Enroll now → Course details Download the syllabus All Computer Science courses Every course with PRO →
Why take it here
Why students take System Analysis and Design with UPI Study
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.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →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?
What is the difference between aggregation and composition in UML?
How do you read multiplicity on a UML association?
What is the difference between a class diagram and an object diagram?
About the System Analysis and Design course
How many college credits is System Analysis and Design?
How much does System Analysis and Design cost and what is included?
Which universities accept UPI Study credits?
How long does System Analysis and Design take?
How are the exams done?
How do my credits reach my college?
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.
3 credits · NCCRSEnroll →