Class Diagram Handouts
Class Diagram Handouts
1. From Functional Model to Object Model: In object oriented software engineering, requirement
elicitation, analysis and design go hand in hand and modelling for one activity leads to a work product
that is used for another activity. Initial requirement elicitation and analysis generates the functional
model of the system (which includes full dressed use cases and use case diagrams) that you have done
till now. Once the initial Functional Model is complete, the next step is to further analyse and design the
system iteratively, resulting in an Object Model. And for object modelling UML class diagram is created.
Note: At this level, note that we are still understanding the application domain. However, many things
discovered in analysis could translate closely into the system design. Goal is to completely understand the
application domain. New insights gained during analysis might cause requirements to be updated.
2. Activities during Object Modelling: analysis and design activities during object modelling include the
following using UML class diagram:
3. Introduction to UML Class Diagram: 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 class diagram shows the domain model of a system
under discussion. It is used during requirements analysis to model application domain concepts during
system design to model subsystems during object design to specify the detailed behavior and attributes
of classes. A class diagram has following parts:
Class Name: A class denotes any entity from the system domain that operates directly ON the
system, FOR the system or IN the system (as its part).So a class name comes from the domain model
and identifies the corresponding concept from the real world. You may begin identifying classes
from the scenarios.
Class Attributes define the structure of a class. May be found by examining class definition, studying
requirements and applying domain knowledge.
4. UML Notation for Classes: In the diagram, classes are represented with boxes that contain three
compartments:
UML provides mechanisms to represent class members, such as attributes and methods, and additional
information about them.
a. Visibility: to specify the visibility of a class member (i.e. any attribute or method), these
notations must be placed before the member's name:
+ Public
- Private
# Protected
~ Package
b. Relationship between Classes: A relationship is a general term covering the specific types of logical
connections found on class and object diagrams. UML defines the following relationships:
Dependency is a weaker form of bond that indicates that one class depends on another because it
uses it at some point in time. One class depends on another if the independent class is a parameter
variable or local variable of a method of the dependent class. It can be thought of as a “uses a”
relationship between classes.
Example: Player and Slingshot classes in “Angry Birds Game”- A player “stretches” a slingshot
to throw birds and play.
d. Association:
This association relationship indicates that (at least) one of the two related classes make reference to
the other. This relationship is usually described as "A has a B" (a student has a teacher). However it
is a relationship where all objects have their own lifecycle and there is no owner. The UML
representation of an association is a solid line connecting the two associated classes.
Multiple students can associate with single teacher and single student can associate with multiple
teachers, but there is no ownership between the objects and both have their own lifecycle. Both can
be created and deleted independently.
e. 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
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.
f. Composition:
Composition is again a specialized form of Aggregation and we can call this as a “death”
relationship. It is a strong type of Aggregation. Child object does not have its lifecycle and if parent
object is deleted, all child objects will also be deleted.“contains a” or “is composed of” relationship.
The UML graphical representation of a composition relationship shows composition as a filled
diamond shape on the containing class end of the lines that connect contained class(es) to the
containing class.
House can contain multiple rooms - there is no independent life of room and any room cannot
belong to two different houses. If we delete the house - room will automatically be deleted.
g. Inheritance/Generalization:
It indicates that one of the two related classes (the subclass) is considered to be a specialized form of
the other (the super type) and the superclass is considered a Generalization of the subclass. In
practice, means that any instance of the subtype is also an instance of the superclass. An exemplary
tree of generalizations of this form is found in biological classification: humans are a subclass of
simian, which is a subclass of mammal, and so on. The relationship is most easily understood by the
phrase 'an A is a B' (a human is a mammal, a mammal is an animal).
The generalization relationship is also known as the inheritance or "is a" relationship. The superclass (base
class) in the generalization relationship is also known as the "parent", superclass, base class, or base type. The
subtype in the specialization relationship is also known as the "child", subclass, derived class, derived type,
h. UML Multiplicity: Multiplicity is a definition of cardinality - i.e. ”How many” instances of some collection of
elements are involved. Provided using inclusive interval of non-negative integers to specify the allowable
number of instances of described element. Multiplicity interval has some lower bound and (possibly infinite)
upper bound.
0 No instances (rare)
0..
1 No instances, or one instance
2. Identifying objects (often from use cases as a starting point) and Associatedbehaviors(use cases):
Perform a textual analysis and select nouns as potential objects/classes.
6. Checking the model against requirements, making adjustments, iterating through the process more than
once.