Software Engineering - Old Questions

11. Explain class diagram with example.

6 marks | Asked in 2068(II)

A class diagram 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.

A UML class diagram is made up of:

  • A set of classes and
  • A set of relationships between classes

Class
A class is a description of a group of objects all with similar roles in the system. A class notation consists of three parts:

UML Class Diagram

Relationships

A class may be involved in one or more relationships with other classes. A relationship can be one of the following types:

1) Generalization: A generalization is a relationship between a parent class (superclass) and a child class (subclass). In this, the child class is inherited from the parent class.

Inheritance

2) AssociationThis kind of relationship represents static relationships between two classes.

Simple association

3) Aggregation: Aggregation is a special type of association that models a whole- part relationship between aggregate and its parts.

Aggregation
Here, Class2 is part of Class1. Many instances (denoted by the *) of Class2 can be associated with Class1.
4) Composition: A special type of aggregation where parts are destroyed when the whole is destroyed.
Composition
Here, Objects of Class2 live and die with Class1. Class2 cannot stand by itself.

Example:  Class diagram for library management system
Archer Tower Printable Diagram Source | Class diagram, Sequence diagram,  Diagram