UML Part1
UML Part1
UML Part1
12/21/2022
Contents
1 Introduction
2 What is UML?
3 UML Diagrams
4 Class Diagram
12/21/2022 3
Example: map
12/21/2022 4
Example: street map (2)
12/21/2022 5
Why model software?
Examples:
• System: Aircraft
• Models: Flight simulator, scale model
• Views: All blueprints, electrical wiring, fuel system
12/21/2022 7
Modeling Notation
View 1
System
View 2
Model 1 View 3
Electrical
Wiring
Scale Model Blueprints
12/21/2022 8
Concepts and Phenomena
• Phenomenon
✓ An object in the world of a domain as you perceive it
✓ Example: The lecture you are attending
✓ Example: You!!
• Concept
✓ Describes the properties of phenomena that are common.
✓ Example: Lectures on software engineering
✓ Example: Trainee
• Concept is a 3-tuple:
✓ Name (To distinguish it from other concepts)
✓ Purpose (Properties that determine if a phenomenon is a member of a
concept)
✓ Members (The set of phenomena which are part of the concept)
12/21/2022 11
Concepts and Phenomena in OO
analysis
Name Purpose Members
• Abstraction
✓ Classification of phenomena into concepts
• Modeling
✓ Development of abstractions to answer specific questions about
a set of phenomena while ignoring irrelevant details.
12/21/2022 12
Example
• Ans. The key is to organize the design process in a way that clients,
analysts, programmers and others involved in system development
can understand and agree on.
12/21/2022 13
What is UML?
12/21/2022 15
Is UML process dependent?
12/21/2022 17
Historical Background (Cont’)
• 1997 – Release of UML 1.1 by IBM, ObjecTime, Platinum,
Ptech, Taskon, Reich and Softeam
• After the first release a task force was formed to improve the
language, which released several minor revisions, 1.3, 1.4,
and 1.5
12/21/2022 19
Benefits of UML
12/21/2022 21
Benefits of UML (Cont’)
12/21/2022 23
Software characteristics
12/21/2022 27
Classes
• The first compartment holds the name of the class, the second holds
attributes, and the third is used for operations.
• You can hide any compartment of the class if that increases the readability
of your diagram.
Attributes:
• Can be simple primitive types (integers, floating-point numbers, etc.) or
relationships to other, complex objects.
• Can be shown using two different notations: inlined or relationships
between classes
• Notation is available to show such things as multiplicity, uniqueness, and
ordering.
• There is no semantic difference between inlined attributes and attributes
by relationship; it's simply a matter of how much detail you want to
present.
• Static attributes are represented by underlining their specification.
12/21/2022 32
Class Diagram (cont.)
Inlined Attributes:
• Lists a class's attributes right in rectangle notation
• It uses the following notation:
visibility / name : type multiplicity = default {property strings and constraints}
{+|-|#} [lower..upper]
Overdrawn=true
if balance < 0
Account
- balance : float
- / Overdrawn : bool
+ transactions : Transactiton [*] {ordered}
12/21/2022 33
Class Diagram (cont.)
Attributes by Relationship:
• Results in a larger class diagram, but it can provide greater detail for
complex attribute types
• Conveys exactly how the attribute is contained within a class
Engine
1 - numCylinders: int
Car
- engine - horsePower: float
+ manufacturer : string
- automatic
Automatic
Car {xor}
Manual
34
12/21/2022 - manual
Class Diagram (cont.)
Operations:
• Features of classes that specify how to invoke a particular behavior.
+ GetSize() : Rectangle
+ SetSize(name : string) : void
+ GetComponents() : Component [0..*]
# Paint() : void
• Operation Constraints:
{Preconditions – Postconditions - Body conditions - Query operations - Exceptions}
12/21/2022 35
Objects
Mohamed:Employee
salary = 500.20
36
12/21/2022
Associations
Department Employee
* * + salary:float
Enumeration getEmployees()
float getSalary(emp)
37
12/21/2022
1-to-1 and 1-to-many Associations
City
Country
1 Has-capital 1
name:String
name:String
One-to-one association
Point
Polygon
* x: Integer
y: Integer
draw()
One-to-many association
38
12/21/2022
From Problem Statement To Object Model
Class Diagram:
StockExchange * * Company
Lists
+ tickerSymbol: int
39
12/21/2022
From Problem Statement to Code
Problem Statement: A stock exchange lists many companies.
Each company is uniquely identified by a ticker symbol
StockExchange * * Company
Lists + tickerSymbol: int
C# Code
public class StockExchange
{
private List<Company> m_Company = new List<Company>();
}
public class Company
{
public int m_tickerSymbol;
private List<StockExchange> m_StockExchange = new List<StockExchange>();
};
40
12/21/2022
Aggregation
Notebook
• An aggregation is a special case of
association denoting a “consists
of” hierarchy.
0..2
• The aggregate is the parent class, Paper
the components are the children
class.
• A solid diamond denotes
composition, a strong form of Rectangle
aggregation denoting a “Contain”
hierarchy
• Note: Rectangle contain Object
from Point * Point
41
12/21/2022
Inheritance relationship
• Inheritance simplifies the model by eliminating
redundancy.
• The children classes inherit the attributes and
operations of the parent class.
• The inheritance denote Kind-Of relationship
Vehicle
43
12/21/2022
Example: Flow of events
44
12/21/2022
Generation of a class diagram
Customer from flow of events
enter() customer enters the store
The customer
buy() to buy a toy
toy. It has to be a
toy that his daughter likes
daughter
?
store and it must cost less than 50
age Euro.
Euro He tries a videogame,
videogame
enter()
which uses a data glove and a
suitable head-mounted display. He likes
it. An assistant helps him.
*
toy The suitability of the game
price depends on the age
age of the
child. His daughter is only 3
like()
years old. The assistant
type of
recommends another type of
videogame boardgame
toy, namely a boardgame.
toy boardgame The
customer buy the game and
12/21/2022
leaves the store 45
Mapping parts of speech to object model
components
• It consists of:
✓ Use cases
✓ Actors
✓ Subjects
Use Case Modeling: Core Elements
Use Case Modeling: Core Elements Cont.’
Use Case Diagram
The use case model is the set of all use cases. It is a complete
description of the functionality of the system and its
environment
12/21/2022 56
Use Case
12/21/2022 57
Use Case Definition: Example
PurchaseTicket
TimeOut
OutOfOrder NoChange
Passenger
• <<includes>> behavior is factored
PurchaseMultiCard out for reuse, not because it is an
exception.
PurchaseSingleTicket <<includes>>
NoChange Cancel
12/21/2022 60