0% found this document useful (0 votes)
102 views

Class Diagram

This document discusses class diagrams in UML. It begins by explaining that class diagrams provide a structural view of object-oriented systems, showing how systems are structured rather than how they behave. It then covers the key components of class diagrams, including classes, attributes, operations, and relationships between classes like association, aggregation, generalization, and dependency. The document provides examples and explanations of how to represent these components in a class diagram, such as showing attributes and operations within classes and using lines and arrows to depict relationships between classes.

Uploaded by

Rawan Basheer
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)
102 views

Class Diagram

This document discusses class diagrams in UML. It begins by explaining that class diagrams provide a structural view of object-oriented systems, showing how systems are structured rather than how they behave. It then covers the key components of class diagrams, including classes, attributes, operations, and relationships between classes like association, aggregation, generalization, and dependency. The document provides examples and explanations of how to represent these components in a class diagram, such as showing attributes and operations within classes and using lines and arrows to depict relationships between classes.

Uploaded by

Rawan Basheer
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

Class Diagram

Eng. Diana Jouhari


UML
Diagram

Behavior Structure
Diagram Diagram

State
Activity Class Component Object
Machine
Diagram Diagram Diagram Diagram Diagram
Composite Deployment Package
Interaction Use Case
structure Diagram Diagram
Diagram Diagram Diagram
Profile
Diagram
Communication Interaction Sequence Timing
Diagram overview Diagram Diagram
Diagram
Class Diagram concept
The UML Class diagram is a graphical notation used to construct and
visualize object oriented systems.

Class diagrams provide a structural view of systems.

Class diagrams capture the static structure of Object-Oriented


systems, or how they are structured rather than how they behave.
Role of Class Diagrams
• Class diagrams are central for analysis, design and implementation.

• Class diagrams are the richest notation in UML.

Activity Use Case Interaction


Diagrams Diagrams Diagrams
inter-class behavior: Structures are refined by scenarios:
describe control flow describe typical interaction
between classes sequences between classes
Class
Diagram
intra-class behavior:
describe states and state
structuring transitions in classes

Package State
Diagrams Diagrams
Class Diagrams components
• Classes

 Attributes

 Operations

• Class Relationships

 Associations

 Generalizations

 Aggregations and Compositions


What is a class
• A class in an object oriented system provides a crisp abstraction of a well
defined set of responsibilities.

• A class is a description of a set of objects that share the same attributes,


operations, relationships, and semantics.

• A class is drawn with a rectangle, usually, divided into three


compartments:
Name
 Name
Attributes
 Attributes
 Operations Operations
Class Name
• The name of the class appears in the first partition.

• The name should be derived from the problem domain and should
be as unambiguous as possible.
Person
• The name should be a noun.
Attributes

Operations
Person

Id: int {readonly}


Class Attributes name : string
address : string
• Attributes are shown in the second partition. birthdate : date
date : date = current date
• The attribute type is shown after the colon. Operations

• Are descriptions of the structural or static features of a class

• Attributes map onto member variables (data members) in code.

• Attribute names typically begin with a lowercase letter.

visibility name : type [multiplicity] = default-value { propertystring}


Class Attributes
• Typical attribute types are integer, Boolean, string, date, real,
floating point, and enumeration, which are called data types.

• An attribute also can have a default value use = .

• A property-string can be used to further describe an attribute.

• A property-string is written within curly braces; it is a comma-


separated list of property values that apply to the attribute
{readOnly},{sequence} ..
Attribute Multiplicity
Multiplicity shows the number of instances of the attribute in square
brackets.
• [0..1] this attribute can have a value of null
• [1..*] this attribute's value is a collection that contains at least one
value
• [*] – this attribute's value is a collection of values Person
• It is omitted if the multiplicity is 1.
name : string
address : string[*]
birthdate : data
Operations
Class Operations (Methods)
• Operations are shown in the third partition.

• They are services the class provides (class behavior).

• The return type of a method is shown after the colon at the end of the
method signature.

• The return type of method parameters are shown


Person
after the colon following the parameter name.
name : string
• Operations are descriptions of behavioral or dynamic
address : string
features of a class birthdate : date
work():int
• Operations map onto class methods in code
Visibility
The attributes and operations can have different visibility.
Visibility describes whether the attribute and operation can be
referenced from classes other than the one in which they are
defined.

+ denotes public attributes or operations it can be used and


viewed outside that class

- denotes private attributes or operations it cannot be accessed


from other classes
Visibility
# denotes protected attributes or operations it is private to the class,
but visible to any subclasses through generalization
/ indicates that the attribute is derived.

Person

+ name : string
# address : string[*]
- birthdate : date
/ age : int
Operations
Visibility Access

Access public private protected


Members of the same class √ √

Members of the derived class √ √

Members of the any other class √


Relationships between classes
• Inheritance

• Association

• Aggregation

• Composition

• Generalization
Inheritance (or Generalization)
Represents an “is-a” relationship. << interface>>

An abstract class name is shown in italics.

Super class

Sub class
Association
A structural link between two peer 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.

There is an association between Class1 and Class2

Class1 Class1
Multiplicity
The number of objects that participate in the association.

Exactly one 1
Zero or more 0..*
One or more 1..*
Zero or one 0..1
Specified range 2..4
Aggregation
A special type of association.
It represents a “partof” relationship.
Class2 is part of Class1.

Class 1 Class 2

office 1 0.. * desk


Composition
A special type of aggregation where parts are destroyed when the
whole is destroyed.
Objects of Class2 live and die with Class1.
Class2 cannot stand by itself.

Class 1 Class 2

Car 1 1..* Door


Dependency
Exists between two classes if changes to the definition of one may
cause changes to the other .
• Class1 depends on Class2

Class 1 Class 2
How to build a class diagram
Producing class diagrams involve the following iterative activities:

• Find classes and associations

• Identify attributes and operations and allocate to classes

• Identify generalization structures


Summary
From Use Cases to Class Diagrams
Order Use case:

• We have customers who order our products.

• We distinguish corporate customers from personal customers, since


corporate customers are billed monthly whereas personal customers need
to prepay their orders.

• We want our orders to be lined up product by product.

• Each line should contain the amount and the price of each product.
Example: Order - Associations

We have customers who may order several products.

* 1
Order customer
Example: Order - Generalization

• We distinguish corporate customers from personal customers, since


corporate customers are billed monthly whereas personal customers
need to prepay their orders with a credit card.

* 1
Order customer

Corporate personal
customer customer
Example: Order - More Associations
• We want our orders to be lined up product by product.
• Each line should contain the amount and the price of each product.

* 1
Order customer
1

*
Order Line Corporate personal
* customer customer
1 product
From Collaboration Diagram to
Class Diagram
View Employee List – Collaboration Diagram
From Sequence Diagram to Class
Diagram
View Employee List – Sequence Diagram
View Employee List _ Class
Diagram
From Collaboration Diagram to
Class Diagram
Pay Salary – Collaboration Diagram
From Sequence Diagram to Class
Diagram
Pay Salary– Sequence Diagram
Pay Salary _ Class Diagram
From Collaboration Diagram to
Class Diagram
Online Order– Collaboration Diagram
From Sequence Diagram to Class
Diagram
Online Order– Sequence Diagram
Online Order_ Class Diagram

You might also like