You are on page 1of 9

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:

• Identifying objects (often from use cases as a starting point)


• Associating behaviors(use cases) of system to appropriate classes
• Identifying associations between objects
• Identifying general attributes and responsibilities of objects
• Modeling interactions between objects.
• Checking the model against requirements, making adjustments, iterating through the
process more than once.

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.

Object-Oriented Analysis and Design


Class Operations define a class’s behaviour. The functionality that a class can execute. These are
derived directly from the use cases in the functional model. Example: “Player” class in the Angry
Birds Game Scenario.

4. UML Notation for Classes: 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 centred, and the first letter is capitalized.

The middle compartment contains the attributes of the


class. They are left-aligned and the attribute name is written
in “Camel case”.

The bottom compartment contains the operations the class


can execute. They are also left-aligned and the name of
function is written in “Camel case”.

The example on the right depicts a class “Player” in a class


diagram for an online game.
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. With
detailed modelling, the classes of the conceptual design are often split into a number of subclasses.

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

/ Derived (can be combined with one of the others)

~ 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:

Object-Oriented Analysis and Design


c. Dependency:

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.

Example: Teacher and Student 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

Object-Oriented Analysis and Design


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.

Example: Department and Teacher classes.

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.

Example: aHouse is composed of Room.

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,

Object-Oriented Analysis and Design


inheriting class, or inheriting type.A is a type of B. For example, "an oak is a type of tree", "an automobile is a type
of vehicle"The UML graphical representation of a Generalization is a hollow triangle shape on the superclass
end of the line (or tree of lines) that connects it to one or more subtypes.

Example: Blue Car “is a kind of” Car

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

1 Exactly one instance

0..* Zero or more instances

* Zero or more instances

1..* One or more instances

How to Create a Class Diagram from a scenario?


Please Follow the example as given by instructor.

Object-Oriented Analysis and Design


CREATING A CLASS DIAGRAM FROM A SCENARIO

Scenario: Angry Birds Game


A player stretches the slingshot back, corrects angle and aims the loaded blue bird at a pig to kill the pig. If there are
ice tiles blocking the way then player hits them first, removes them and then targets the pig. When the tile breaks it
disappears (pops) and when the pig is hit it disappears too.A bonus is shown to user every time a pig is killed. The
user can tap the blue bird while it is flying to split them into 3 birds.The bird either hits the target or misses it. On each
miss a new bird is loaded in the slingshot.

Following are two relevant snapshots of the game:

Object-Oriented Analysis and Design


Steps:

1. Create a functional model (use case diagram)

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.

Object-Oriented Analysis and Design


3. Identifying associations between objects
4. Identifying general attributes and responsibilities of objects
5. Modeling interactions between objects.

6. Checking the model against requirements, making adjustments, iterating through the process more than
once.

Object-Oriented Analysis and Design


Object-Oriented Analysis and Design

You might also like