ArticleslgStudy

science

Class diagram

Class diagram is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Class diagram rather than just read about it. In short: In software engineering, a class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that describes the structure of a system by showing the system's classes, their attributes, operations (or methods), and the relationships among objects. The class diagram is the main building block of object-oriented modeling.

Class diagram — main illustration
Class diagram — illustration

Key takeaways

  • Class diagram belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Class diagram to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Class diagram from memory before moving on to harder problems.

Reference excerpt

In software engineering, a class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that describes the structure of a system by showing the system's classes, their attributes, operations (or methods), and the relationships among objects. The class diagram is the main building block of object-oriented modeling. It is used for general conceptual modeling of the structure of the application, and for detailed modeling, translating the models into programming code. Class diagrams can also be used for data modeling. The classes in a class diagram represent both the main elements, interactions in the application, and the classes to be programmed. In the diagram, classes are represented with boxes that contain three compartments:

The top compartment contains the name of the class. It is printed in bold and centered, and the first letter is capitalized. The middle compartment contains the attributes of the class. They are left-aligned and the first letter is lowercase. The bottom compartment contains the operations the class can execute. They are also left-aligned and the first letter is lowercase. In the design of a system, a number of classes are identified and grouped together in a class diagram that helps to determine the static relations between them. In detailed modeling, the classes of the conceptual design are often split into subclasses. In order to further describe the behavior of systems, these class diagrams can be complemented by a state diagram or UML state machine.

Members UML provides mechanisms to represent class members, such as attributes and methods, and additional information about them like constructors.

Visibility To specify the visibility of a class member (i.e. any attribute or method), these notations must be placed before the members' name:

A derived property is a property whose value (or values) is produced or computed from other information, for example, by using values of other properties. A derived property is shown with its name preceded by a forward slash '/'.

Scope The UML specifies two types of scope for members: instance and class. The class name appears an underlined concatenation of the instance name (if any), a colon (':'), and the actual class name.

Instance members are scoped to a specific instance. Attribute values may vary between instances Method invocation may affect the instance's state (i.e. change instance's attributes) Class members are commonly recognized as "static" in many programming languages. The scope end is the class itself. Attribute values are equal for all instances Method invocation does not affect the classifier's state To indicate a classifier scope for a member, its name must be underlined. Otherwise, instance scope is assumed by default.

Relationships

A relationship is a general term covering the specific types of logical connections found on class and object diagrams. UML defines the following relationships:

Instance-level relationships

Dependency A dependency is a type of association where there is a semantic connection between dependent and independent model elements. It exists between two elements if changes to the definition of one element (the server or target) may cause changes to the other (the client or source). This association is uni-directional. A dependency is displayed as a dashed line with an open arrow that points from the client to the supplier.

Association

An association represents a family of structural links. A binary association is represented as a solid line between two classes. A reflexive association is a binary association between the class and itself. An association between more than two classes is represented as a diamond connected with a solid line to each of the associated classes. An association between three classes is a ternary association. An association between more classes is called an n-ary association. An association can be named, and the ends of an association can be adorned with role names, aggregation indicators, multiplicity, visibility, navigability and other properties. The dot notation for example allows to represent with a little dot on the side of one class that the association end is owned by the other side. There are three types of association: simple association, shared aggregation, composite aggregation (composition). An association can be navigable in one or more directions. The navigability does not have to be explicitly specified. An open-headed arrow on the side of a class documents that the class can be reached efficiently at run-time from the opposite side. A unidirectional navigation is shown with a little cross on the association line on the side of the class that cannot be reached. For instance, a flight class is associated with a plane class bi-directionally.

Aggregation

Aggregation is a variant of the "has a" association relationship; aggregation is more specific than association. It is an association that represents a part-whole or part-of relationship. As shown in the image, a Professor 'has a' class to teach. As a type of association, an aggregation can be named and have the same adornments that an association can. However, an aggregation may not involve more than two classes; it must be a binary association. Furthermore, there is hardly a difference between aggregations and associations during implementation, and the diagram may skip aggregation relations altogether. Aggregation can occur when a class is a collection or container of other classes, but the contained classes do not have a strong lifecycle dependency on the container. The contents of the container still exist when the container is destroyed. In UML, it is graphically represented as a hollow diamond shape on the containing class with a single line that connects it to the contained class. The aggregate is semantically an extended object that is treated as a unit in many operations, although physically it is made of several lesser objects.

Composition

The composite aggregation (colloquially called composition) relationship is a stronger form of aggregation where the aggregate controls the lifecycle of the elements it aggregates. The graphical representation is a filled diamond shape on the containing class end of the line that connect contained class(es) to the containing class.

… excerpt ends here. Continue reading the full article.

Illustrations

Class diagram: Hierarchy of UML 2.5 Diagrams, shown as a class diagram. The individual classes are represented just with one compartment, but they often contain up to three compartments.
Hierarchy of UML 2.5 Diagrams, shown as a class diagram. The individual classes are represented just with one compartment, but they often contain up to three compartments.
Class diagram: A class with three compartments
A class with three compartments
Class diagram: UML relations notation
UML relations notation
Class diagram: Two class diagrams. The diagram on top shows Composition between two classes: A Car has exactly one Carburetor, and a Carburetor is a part of one Car. Carburetors cannot exist as separate parts, detached from a specific car. The diagram on bottom shows Aggregation between two classes: A Pond has zero or more Ducks, and a Duck has at most one Pond (at a time). Duck can exist separately from a Pond, e.g. it can live near a lake. When we destroy a Pond we usually do not kill all the Ducks.
Two class diagrams. The diagram on top shows Composition between two classes: A Car has exactly one Carburetor, and a Carburetor is a part of one Car. Carburetors cannot exist as separate parts, detached from a specific car. The diagram on bottom shows Aggregation between two classes: A Pond has zero or more Ducks, and a Duck has at most one Pond (at a time). Duck can exist separately from a Pond, e.g. it can live near a lake. When we destroy a Pond we usually do not kill all the Ducks.
Class diagram: Class diagram showing generalization between the superclass Person and the two subclasses Student and Professor
Class diagram showing generalization between the superclass Person and the two subclasses Student and Professor

Worked examples

Example 1 — a first encounter with Class diagram

Start with the simplest possible case. Write down what Class diagram claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Class diagram before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Class diagram ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Class diagram

In research
Class diagram appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Class diagram in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Class diagram is common in secondary-school and first-year university syllabi. It links to neighbouring topics Unified Modeling Language diagrams, so understanding it makes those chapters shorter.
In everyday life
Look for Class diagram outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Class diagram” →

How to study Class diagram in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Class diagram means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Class diagram out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Class diagram in simple terms?

In software engineering, a class diagram in the Unified Modeling Language (UML) is a type of static structure diagram that describes the structure of a system by showing the system's classes, their attributes, operations (or methods), and the relationships among objects. The class diagram is the ma…

Why does Class diagram matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Class diagram?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Class diagram.

Tags

  • Unified Modeling Language diagrams

Keep exploring