0% found this document useful (0 votes)
2 views40 pages

Lecture2 Class Diagrams

The document provides an overview of the Unified Modeling Language (UML), a visual language used for modeling and communicating about systems through diagrams. It covers the structure of class diagrams, including attributes, operations, responsibilities, and relationships such as association, aggregation, and composition. Additionally, it discusses the importance of UML in object-oriented design and analysis, as well as the role of the Object Management Group in its development.

Uploaded by

naomingunda788
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views40 pages

Lecture2 Class Diagrams

The document provides an overview of the Unified Modeling Language (UML), a visual language used for modeling and communicating about systems through diagrams. It covers the structure of class diagrams, including attributes, operations, responsibilities, and relationships such as association, aggregation, and composition. Additionally, it discusses the importance of UML in object-oriented design and analysis, as well as the role of the Object Management Group in its development.

Uploaded by

naomingunda788
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

The University of Dodoma

Department of Computer Science


CS 314: Object Oriented Program Design and Analysis
Lecture 2: Unified Modeling Language (UML) (Class Diagrams)
Definition
● Quite simply, the UML is a visual language for modeling
and communicating about systems through the use of
diagrams and supporting text.
● UML resulted from the merging of three very popular
Object Oriented Design methods by Grady Booch,
James Rumbaugh, and Ivar Jacobson.
● The three worked in separate organizations through the
1980s and early 1990s, each devising his own
methodology for object-oriented analysis and design.
● UML is now under the control of the Object
Management Group (OMG) Check for updates at the
OMG Web site, http://www.omg.org
UML uses ...
UML different views ...
Definition ...
● UML consists of a number of graphical elements that
combine to form diagrams
● The diagrams is to present multiple views of a system;
this set of multiple views is called a model.
● In our discussion, a model is a set of UML diagrams
that we can examine, assess, and modify in order to
understand and develop a system.
● A UML model describes what a system is supposed to
do. It doesn't tell how to implement the system.
● UML has a number of diagrams, each providing a
certain view of your system. But we will concentrate
with common ones (with **) (refer next slide)
UML ...
Class and Objects Diagrams
● UML notation :A rectangle is the icon that
represents the class. Its divided into three
areas. The uppermost area contains the name,
the middle area holds the attributes, and the
lowest area holds the operations.
● Class of washing machines has attributes such
as brand name, model, serial number, and
capacity. Behaviors for things in this class
include the operations ”accept clothes”, ”accept
detergent”, ”turn on”, and ”turn off.”
Class and Objects Diagrams ...
Class and Objects Diagrams ...
● Sometimes more details can be added to
attributes and member functions/methods like:
– Method parameters, return types and visibility.
– To indicate a type, use a colon to separate the
attribute name from the type. You can also indicate
a default value for an attribute e.g.
(name:string=”default value”).
Class Attributes
● A class attribute (static attribute, static member)
is an attribute assigned to a class and not to a
single object (as instance of the class). In C++
we use static keyword to define such attributes.
A static attribute has the same value for all
object instances of a class.
● In a class diagram, static attributes are
underlined. Example:
-numberOfInvoices:Integer
Objects
● Every object of the class has a specific value
for every attribute.
● Objects name begins with a lowercase letter,
precedes a colon that precedes the classname,
and the whole name is underlined.
● The name myWasher:WashingMachine is a
named instance. It is also possible to have an
anonymous instance like :WashingMachine
Objects ...
Responsibilities and Constraints
● The class icon enables you to specify the class
responsibility.
● The responsibility is a description of what the class
has to do that is, what its attributes and operations
are trying to accomplish.
● In the icon, you indicate responsibilities in an area
below the area that contains the operations (see next
slide).
● Can also add a constraint, a free-form text enclosed
in curly brackets. The bracketed text specifies one or
more rules the class follows. Example: (capacity = 16
or 18 or 20 lbs). See next slide
Responsibilities and Constraints ...
More on Constraints
● The UML works with still another and much
more formal way of adding constraints that make
definitions more explicit. Its an entire language
called Object Constraint Language (OCL).
● An advanced and sometimes useful tool, OCL
has its own set of rules, terms, and operators.
The Web site of the Object Management Group
(http://www.omg.org) provides documentation on
OCL.
Attached Notes
● In addition to attributes, operations,
responsibilities, and constraints, you can add
still more information to a class in the form of
notes attached to the class. You'll usually add a
note to an attribute or operation.
Attached Notes
UML symbols for Inheritance
UML symbols for Inheritance
● In the UML, you represent inheritance with a
line that connects the parent class to the child
class (or superclass to the subclass).
● On the part of the line that connects to the
parent class, you put an open triangle that
points to the parent class.
More on Class Diagrams
Class Relationships
● Classes rarely stand alone; instead, they
collaborate with other classes in a variety of
ways. The essential connections among classes
include:
– Association
– Generalization
– Aggregation
– and Composition
● Each such relationship may include a textual
label that documents the name of the
relationship or suggests its purpose.
Class Relationship ...
● Association -- a relationship between instances of
the two classes. There is an association between
two classes if an instance of one class must know
about the other in order to perform its work.
● Aggregation -- an association in which one class
belongs to a collection. An aggregation has a
diamond end pointing to the part containing the
whole.
● Generalization -- an inheritance link indicating one
class is a superclass of the other. A generalization
has a triangle pointing to the superclass.
UML Generalization representation
Association
● Relationships between instances (objects) of
classes
● Conceptual:
– associations can have two roles (bi-directional):
● source --> target
● target --> source
– roles have multiplicity (e.g., cardinality, constraints)
– To restrict navigation to one direction only, an
arrowhead is used to indicate the navigation direction
● No inheritance as in generalizations
Association
Multiplicities
Aggregation (shared aggregation)
● Is a specialized form of ASSOCIATION in which
a whole is related to its part(s).
● Is known as a “part of” or containment
relationship and follows the “has a” heuristic
● Three ways to think about aggregations:
– whole-parts
– container-contents
– group-members
Composition (composite
aggregation):
● Is a stronger version of AGGREGATION
● The “part(s)” may belong to only ONE whole
● The part(s) are usually expected to “live” and
“die” with the whole (“cascading delete”).
(another: assembly --> part) (another: hand --> finger)
Composition
● Composition is often used in place of
Generalization (inheritance) to avoid
“transmuting” (adding, copying, and deleting of
objects)
Association, Aggregation and
Composition
Multiplicity Example #1
Whole

3
1
5 2
Part1 PartN

● One Whole is associated with 5 Part1 ● One Whole is associated with 2 PartN
● One Part1 is associated with 1 Whole ● One PartN is associated with 3 Whole

P
P W
P
W P P W
P W P
P
W W
P

32
Multiplicity Example #2
Class1

max. 1 2..5
min.
1..n
0..*
Class2 Class3

1..n * C3 2..5 C1
C2 1 C1
C3
C1
C2 C3 C1
C2 C1 C3
C1 C2 C1
C3
C2 C1
C3
C2
etc... etc...

33
Multiplicity Example #3

FacultyInformation StudentInformation

1 0..* 1 1 1

1..* 0..*
0..*
DegreeHeld CommitteeAssign
CourseCompleted

0..* 0..*
CourseTeach ClubMember

34
StudentInformation CourseInformation
0..*
attributes attributes
operations 0..* operations

StudentInformation CourseInformation StudentInformation CourseInformation


0..*
attributes attributes attributes attributes
0..*
operations operations operations operations

1 1
0..* 0..*

StudentCourseInformation StudentCourseInformation
SemesterTaken SemesterTaken
GradeEarned GradeEarned

operations operations

35
Reflexive Association Relationships
Objects within the same class have a
relationship with each other.

Course
0..*

is pre-requisite for

0..*
has pre-requisite of

36
Video Store – UML Class Diagram
1 1
Inventory

SaleItem RentalItem

Video Game ConcessionItem VCR

0..* 0..*
Transaction Employee StoreLocation
1 1

SaleTransaction RentalTransaction Suplier


1 0..* 0..* 1 1
0..1 1 0..*
Member PurchaseOrder
1..* 1..* 1
SaleRentalLineItem 1..*
0..* 0..*
PurchaseOrderLineItem

37
38
39
40

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy