Class Diagram
Class Diagram
Diagrams
1
In UML:
• A model is represented graphically in the form of diagrams.
• A Diagram provides a view of that part of reality described by
the model.
• There are diagrams that
o Express which users use which functionality
o Diagrams that show the structure of the system but
without specifying a concrete implementation.
2
Class Diagram:
• Class diagram is used to describe the structure of the
system.
• It describes the system in terms of classes, object, attributes,
operations and their associations.
• Classes are abstractions.
• Objects are instances of classes that are created, modified,
and destroyed during the execution of the system.
• An object has state that includes the values of its attributes
and its links with other objects.
3
Relationships in Class diagram
Associations:
• Association is a simple structural connection between classes.
• It is as representing a "peer" relationship.
• Instances of classes involved in an association which
Binary Association
communicating with each other at program execution time.
• There are two basic kinds of associations:
o Binary associations
o N-ary associations.
N-ary Association
4
Navigability, roles, and multiplicity:
Navigability:
• It can be only occur navigate from one
class to another by using a feathered
arrow.
Multiplicity: Roles:
•An association can show multiplicity. • An association can contain roles, which
are the faces that classes present to
other classes.
5
Aggregation:
• An aggregation is a special kind of association.
• It is a "whole/part" relationship within which one or more classes
are parts of a larger whole.
• A class can be aggregated to one or more other classes.
• An aggregation appears as a line with an open diamond at one end.
• The class next to the diamond is the whole class; the class at the
other end of the line is the part class.
6
Composition:
• Composition is a "strong" form of aggregation.
• Differences between composition and aggregation, as follows:
• Within a composition relationship, the whole and the parts have
coincident lifetimes.
• This means that if a particular instance of the whole is destroyed,
so are the instances of the parts.
• A class can only belong to one composition relationship at a time
as a part.
7
Generalization:
• It refers to a relationship between a general class (the
superclass or parent) and a more specific version of
that class (the subclass or child ).
• A generalization appears as a line with an open triangle at
one end.
• The class next to the triangle is the parent/superclass;
the class at the other end of the line is the
child/subclass.
8
Dependency:
•A dependency is a "using" relationship within which a change
in one thing (such as a class) may affect another thing (for
instance, another class).
•The dependent element is called the client or source the
independent element is called the supplier or target.
•A dependency involving two classes appears as a dashed line
with a feathered arrow pointing at the supplier.
9
Association Class:
•An association class is a cross between an association and
a class.
•Association class decomposes many-to-many
relationships into one-to-many relationships.
10
Visibility: Account
• The visibility of an attribute or an operation specifies whether -emailAddress
objects that belong to other classes can "see" that attribute or -ID
operation. -Password
o Package visibility(~): means that objects belonging to
any class in the same package as the given class can see
and use the given class it. Review
o Public visibility(+) : means that objects belonging to #record()
any class can use the given attribute or operation.
o Protected visibility(#): means that only objects that customerReview
belong to subclasses of the given class
+assignRating
o Private visibility (-) : means that only objects -computeAvgRating
belonging to the class itself can use the attribute.
11
Multiplicity:
• It indicates how many of one thing can exist relative to
another thing.
• A multiplicity expression can take several forms,
including the following:
o A fixed value (such as 1 or 3)
o An asterisk (*), which means "many”
o A range of values, expressed as lower… upper
(for instance, 0…1 or 3…*)
o A set of values (for example, [1, 3, 5, 7])
12
Levels of Class Diagram
13
Domain Level Class diagram:
14
Analysis Level Class Diagram:
15
Design Level Class Diagram:
•Once a project starts exploring design issues, class
diagrams tend to be more varied.
•Classes can expand using the full UML notation, or
•Classes can explore at a lower level of abstraction and
continue to suppress the details.
•One form of design-level class diagram is simply a more
expansive version of an analysis-level diagram.
16
Example 1:
17
Example 2:
•For example, the following shows a set of classes drawn from the
implementation of an autonomous robot.
•The figure focuses on the classes involved in the mechanism for
moving the robot along a path.
•You'll find one abstract class (Motor) with two concrete children,
SteeringMotor and MainMotor. Both of these classes inherit the
five operations of their parent, Motor.
•The two classes are, in turn, shown as parts of another class, Driver.
•The class PathAgent has a one-to-one association to Driver and a
one-to-many association to CollisionSensor.
•No attributes or operations are shown for PathAgent, although its
responsibilities are given
18
Example 3:
19
Exercise:
Draw a UML Class Diagram representing the following elements from the problem domain for
a hockey league.
A hockey league is made up of at least four hockey teams. Each hockey team is composed of six to
twelve players, and one player captains the team. A team has a name and a record. Players have a
number and a position. Hockey teams play games against each other. Each game has a score and a
location. Teams are sometimes lead by a coach. A coach has a level of accreditation and a number of
years of experience, and can coach multiple teams. Coaches and players are people, and people have
names and addresses.
20
THANK YOU!!!
21