+ All Categories
Home > Education > Lecture-03 Introduction to UML

Lecture-03 Introduction to UML

Date post: 06-May-2015
Category:
Upload: artgreen
View: 3,287 times
Download: 1 times
Share this document with a friend
Description:
Introduction to UML
Popular Tags:
58
Computer Engineering Department Object Oriented Software Modeling and Design CE 350 Abdel-Karim Al-Tamimi, Ph.D. [email protected] http:// faculty.yu.edu.jo/ altamimi Al-Tamimi 2011 © 1
Transcript
Page 1: Lecture-03 Introduction to UML

Computer Engineering Department

Computer Engineering Department

Object Oriented Software Modeling and Design

CE 350Abdel-Karim Al-Tamimi, Ph.D.

[email protected]://faculty.yu.edu.jo/

altamimi

Al-Tamimi 2011 © 1

Page 2: Lecture-03 Introduction to UML

Overview

• Introduction UML

Al-Tamimi 2011 © 2

Page 3: Lecture-03 Introduction to UML

UML Definition and Usage

• UML stands for : Unified Modeling Language

• UML helps in facilitating:– Specification– Visualization– Architecture Design– Construction– Simulation and Testing– Documentation

Al-Tamimi 2011 © 3

Page 4: Lecture-03 Introduction to UML

UML Basics

• A model helps getting an abstract idea of the objects the software product consists of and their interactions– Employ information hiding in the model

• Model’s point of view is important to determine the final shape of the diagram and the necessary information to be included –Use-case diagram vs. Class diagram

Al-Tamimi 2011 © 4

Page 5: Lecture-03 Introduction to UML

Using Models/Diagrams

• It is easier to change models than code

• Allow non-technical team members/ clients to understand the structure of the system and be active in decision making

• Client can check if the system’s design is confined to the agreed-on requirements

Al-Tamimi 2011 © 5

Page 6: Lecture-03 Introduction to UML

Types of Diagrams

• There are several types of diagrams :–Use-Case Diagrams– Activity Diagrams– Class Diagrams– Interaction Diagrams– State Diagrams

Al-Tamimi 2011 © 6

Page 7: Lecture-03 Introduction to UML

Types of Diagrams

Al-Tamimi 2011 © 7

Page 8: Lecture-03 Introduction to UML

UML: Fundamental Level

• The first level examines fundamental UML knowledge, including basic notions on class diagrams, activity diagrams, interaction diagrams, and use case diagrams, as well as various elements such as standard stereotypes and primitive types

• These basics include not only the elements visible to UML users, but also abstract UML concepts, such as Element—the base class for all UML classes in the metamodel

Al-Tamimi 2011 © 8

Page 9: Lecture-03 Introduction to UML

Use Case Diagram: Introduction

• It lists the capabilities of the system (including their users)

• Documents the macro requirements of the system

Al-Tamimi 2011 © 9

Borrow Book

Borrow Book

Student

Page 10: Lecture-03 Introduction to UML

Activity Diagram

• In UML an activity diagram is a version of flowchart

• Activity diagrams are used to analyze processes, or even process re-engineering

• Very helpful in understanding the overall process without indulging in technical issues

• Explains the steps (actions) the user takes to achieve a certain milestone/milestones

• There are a Start point and an End point

Al-Tamimi 2011 © 10

Page 11: Lecture-03 Introduction to UML

Activity Diagram: Example

Al-Tamimi 2011 © 11

Leave HouseLeave House

Take ClassTake Class Wander AroundWander Around

Return to House

Return to House

Take another Class

Done for today ?

Arrive to university

End of day

Page 12: Lecture-03 Introduction to UML

Class Diagram

• Show the classes in the system and the relationships between these classes

• There are many possible class diagrams, and a single class can be shown in more than one class diagram

• Show the classes and their relationships in the best way to understand the system

• Does not explain the classes interactions, just a static view of the system

Al-Tamimi 2011 © 12

Page 13: Lecture-03 Introduction to UML

Class Diagrams: Example

Al-Tamimi 2011 © 13

StudentStudentBookBook

ReferenceReferenceMagazineMagazine

Page 14: Lecture-03 Introduction to UML

Interaction Diagrams

• Interaction diagram are categorized into:– Sequence diagrams• Models a single flow, the classes are on top

– Collaboration diagrams• Messages and classes are organized in the spatial

space, no single flow

• These diagram represent the same information using different perspectives

• Shows objects and messages between them

Al-Tamimi 2011 © 14

Page 15: Lecture-03 Introduction to UML

Interaction Diagrams – Sequence Diagram

Al-Tamimi 2011 © 15

StudentStudent BookBook LibraryLibrary

Walk to school

Access Library

Browse Book

Borrow book

Read book

Page 16: Lecture-03 Introduction to UML

Interaction Diagrams – Collaboration Diagram

Al-Tamimi 2011 © 16

BookBook

StudentStudent

LibraryLibrary

1-Walk to school5-Read book

3-Browse book4-Borrow book

2-Access library

Page 17: Lecture-03 Introduction to UML

State Diagram

• Shows the changing state of a single object as it passes through the system

Al-Tamimi 2011 © 17

WalkingWalkingLeave

the house

StudyingStudyingArrive

to School

/ take classDone

RestingRestingHave a break

Yes

Page 18: Lecture-03 Introduction to UML

UML Notations

Al-Tamimi 2011 © 18

Page 19: Lecture-03 Introduction to UML

UML Notation of Objects and Classes

Al-Tamimi 2011 © 19

ClassClass

ObjectObject

- indicates private attributes/methods+ indicates public attributes/methods# indicates protected attributes/methods~ indicates package visible attributes/methods

Notice the naming conventionBankAccount

BankAccountBankAccount

- name- balance- name- balance+ debit (int amount): void+ credit (int amount): void

+ debit (int amount): void+ credit (int amount): void

Object1 : BankAccountObject1 : BankAccount

name = John Smithbalance = 1,000name = John Smithbalance = 1,000

Object2 : BankAccountObject2 : BankAccount

name = Robert Jonesbalance = -200name = Robert Jonesbalance = -200

Page 20: Lecture-03 Introduction to UML

Visibility / Access ModifiersReview

• Public : visible to all elements that can access the contents of the namespace that owns it

• Private: only visible inside the namespace that owns it

• Protected: visible to elements that have a generalization relationship to the namespace that owns it

• Package: Any element marked as having package visibility is visible to all elements within the nearest enclosing package

Al-Tamimi 2011 © 20

Page 21: Lecture-03 Introduction to UML

UML Class Example

Al-Tamimi 2011 © 21

StudentStudent

-StudentName:String-StudentID:Integer-DOB:DateTime-GPA:Double=0.0

-StudentName:String-StudentID:Integer-DOB:DateTime-GPA:Double=0.0

+ getGPA():Double+ setName(Name:String)- CalculateGPA():Double

+ getGPA():Double+ setName(Name:String)- CalculateGPA():Double

Page 22: Lecture-03 Introduction to UML

Relationships between Classes

• There are essentially four important types of relationships between classes: –Generalization/specialization

• Inheritance– Aggregation (“part-of”)– Association

• Role and the connection between the classes– Realization

• one model element (the client) realizes the behavior that the other model element (the supplier) specifies

Al-Tamimi 2011 © 22

Page 23: Lecture-03 Introduction to UML

Generalization / Specialization Relationship

Al-Tamimi 2011 © 23

BankAccount attributes and methods are not specified

again

BankAccount attributes and methods are not specified

again

New attribute “interest” is shown in the

subclass

New attribute “interest” is shown in the

subclass

Generalization

Generalization

Specialization

Specialization

Page 24: Lecture-03 Introduction to UML

Generalization / Specialization Relationship• An abstract class is used to specify the

required behaviors (operations) of a class, without having to provide their actual implementations

• An operation without the implementation (body) is called an abstract operation

• A class with one or more abstract operations is an abstract class

• An abstract class cannot be instantiated because it does not have the required implementation of the abstract operations

Al-Tamimi 2011 © 24

Page 25: Lecture-03 Introduction to UML

Association Relationship

• Object-oriented systems are made up of objects of many classes. Associations represent relationships among classes

• An association is represented by a line drawn between the associated classes involved with an optional role name attached to either end

• The role name is used to specify the role of an associated class in the association

• If an association connects two objects instead of classes, it is called a link

• A link is an instance of an association.

Al-Tamimi 2011 © 25

Page 26: Lecture-03 Introduction to UML

Association Relationship

Al-Tamimi 2011 © 26

Name of Link

Multiplicity

Role

Name of Association

Page 27: Lecture-03 Introduction to UML

Multiplicity

Al-Tamimi 2011 © 27

UML Multiplicity Meaning

1 Exactly 1 (default)

2 Exactly 2

1..3 From 1 to 3 inclusive

3, 5 Either 3 or 5

1..* At least [1], and at most [unlimited]

* Unlimited (including 0)

0..1 Either 0 or 1

Page 28: Lecture-03 Introduction to UML

Multiplicity: Example

Al-Tamimi 2011 © 28

StudentStudent BookBook

borrows

0..1 0..5

ProfessorProfessorborro

ws

*

0..1

Page 29: Lecture-03 Introduction to UML

Qualification Relationship

• Qualification serves as names or keys that are part of the association and are used to select/qualify objects across the association at the other end

• In UML, a qualifier is used to model this association semantic, that is an association attribute whose value determines a unique object or a subset of objects at the other end of an association

• The qualifier goes at the opposite end of the association from the class of which it’s an attribute

Al-Tamimi 2011 © 29

Page 30: Lecture-03 Introduction to UML

Qualification Relationship

Al-Tamimi 2011 © 30

Account Number a single person

Account number acted as a filter

Page 31: Lecture-03 Introduction to UML

Qualification Relationship: Example

Al-Tamimi 2011 © 31

DriverDriver vehiclevehicledrives

But if he can only drive 4 wheels vehicles:

DriverDriver vehiclevehicledrives

4 wheels

4 wheels

What if he can only drive his own car:

DriverDriver vehiclevehicledrives

License plate

License plate

Page 32: Lecture-03 Introduction to UML

Reflexive Associations

• Relates one object of a class to another object of the same class

• In other words, a class can be associated with itself

• Reflexive associations are two types– directional – and bi-directional

Al-Tamimi 2011 © 32

Page 33: Lecture-03 Introduction to UML

Reflexive Association: Example

Al-Tamimi 2011 © 33

Page 34: Lecture-03 Introduction to UML

Reflexive Association: Example

Al-Tamimi 2011 © 34

Directional Bi-directional

Page 35: Lecture-03 Introduction to UML

Association Classes

Al-Tamimi 2011 © 35

Sometimes, it is necessary to describe an association by including some attributes which do not naturally belong to the objects involved in the association

Enrollment is an association class

Page 36: Lecture-03 Introduction to UML

Association Classes: Example

Al-Tamimi 2011 © 36

Can a person have multiple positions at the same company ?

Page 37: Lecture-03 Introduction to UML

N-ary Association

Al-Tamimi 2011 © 37

Page 38: Lecture-03 Introduction to UML

N-ary Association

Al-Tamimi 2011 © 38

3 or a Ternary association

Page 39: Lecture-03 Introduction to UML

N-ary Association

Al-Tamimi 2011 © 39

decomposed

Page 40: Lecture-03 Introduction to UML

Aggregation Relationship• Aggregation is a stronger form of association • It represents the has-a or part-of relationship• In UML, a link is placed between the “whole”

and the “parts” classes with a diamond head attached to the “whole” class to indicate that this association is an aggregation

• Multiplicity can be specified at the end of the association for each of the “part-of” classes to indicate the quantity of the constituent parts

• Typically, aggregations are not named, and the keywords used to identify aggregations are “consists of”, “contains” or “is part of”

Al-Tamimi 2011 © 40

Page 41: Lecture-03 Introduction to UML

Aggregation : Example

Al-Tamimi 2011 © 41

Page 42: Lecture-03 Introduction to UML

Aggregation: Example

Al-Tamimi 2011 © 42

CompanyCompany

warehousewarehouse SalesmanSalesman StoreStore

0..*

1..*

0..*

0..* 1..* 0..*

Page 43: Lecture-03 Introduction to UML

Composition Relationship

• A stronger form of aggregation is called composition, which implies exclusive ownership of the “part-of” classes by the “whole” class, i.e. a composite object has exclusive ownership of the parts objects

• This means that parts may be created after a composite is created, but such parts will be explicitly removed before the destruction of the composite

• It is represented using a filled diamond head

Al-Tamimi 2011 © 43

Page 44: Lecture-03 Introduction to UML

Composition: Example

Al-Tamimi 2011 © 44

Page 45: Lecture-03 Introduction to UML

Composition: Example

Al-Tamimi 2011 © 45

ReportReport

TitleTitle ColumnColumn FigureFigure

1

1

1

1..* 1..* 0..*

Page 46: Lecture-03 Introduction to UML

General Notes

• Generalization indicates "is-a” relationship

• Composition indicates “part-of” relationship

• Aggregation indicates “has-a” relationship

Al-Tamimi 2011 © 46

CarCar EngineEngine PersonPerson AddressAddress

BookBook Reference

Reference

Page 47: Lecture-03 Introduction to UML

Difference Between Aggregation and Composition

Relationships• When attempting to represent real-world

whole-part relationships, e.g., an engine is part of a car, the composition relationship is most appropriate– A department belongs to only one university

• When representing a software or database relationship, e.g., ConvertToPDF component is a part of a software library Printing, an aggregation relationship is best

• Aggregation - Without whole part can exist. Composition - Without whole part can't exit.

Al-Tamimi 2011 © 47

Page 48: Lecture-03 Introduction to UML

Dependency Relationship

• Dependency is a weaker form of relationship which indicates that one class depends on another because it uses it at some point of time

• Dependency exists if a class is a parameter variable or local variable of a method of another class– The class uses the other’s class object(s) in its

runtime– In use-case diagrams is used to indicate that a

change to the supplier might require a change to the client

Al-Tamimi 2011 © 48

Page 49: Lecture-03 Introduction to UML

Dependency Relationship: Example

Al-Tamimi 2011 © 49

ServerServer DatabaseConnectionManager

DatabaseConnectionManager<<use>>

Page 50: Lecture-03 Introduction to UML

Dependency Relationships in UML (1 of 2)

Type of Dependency

Keyword Description

Abstraction «abstraction», «derive», «refine», or «trace»

Relates two model elements, or sets of model elements, that represent the same concept at different levels of abstraction, or from different viewpoints

Binding «bind» Connects template arguments to template parameters to create model elements from templates

Al-Tamimi 2011 © 50

Page 51: Lecture-03 Introduction to UML

Dependency Relationships in UML (2 of 2)

Type of Dependency

Keyword Description

Realization «realize» Indicates that the client model element is an implementation of the supplier model element, and the supplier model element is the specification

Substitution «bind» Indicates that the client model element takes the place of the supplier; the client model element must conform to the contract or interface that the supplier model element establishes

Usage «use», «call», «create», «instantiate», or «send»

Indicates that one model element requires another model element for its full implementation or operationAl-Tamimi 2011 © 51

Page 52: Lecture-03 Introduction to UML

Realization Relationship

• In this relationship, one element realizes the behavior that the other element specifies

• Usually associated with class and component diagrams

• Usually represents the relationship between an interface (abstract class) and a sub-class that implements the interface

Al-Tamimi 2011 © 52

Page 53: Lecture-03 Introduction to UML

Realization Relationship: Example

Al-Tamimi 2011 © 53

Payable<<interface>

>

Payable<<interface>

>

EmployeeEmployeeInvoiceInvoice

SalaryEmployee

SalaryEmployee

Page 54: Lecture-03 Introduction to UML

Constraints and Notes

• Constraints are an extension of the semantics of a UML element, allowing one to add new rules or modify existing ones. Sometimes it is helpful to present an idea about restrictions on attributes and associations for which there is no specific notation

• Constraints are represented by a label in curly brackets ({constraintName} or {expression}) that are attached to the constrained element

Al-Tamimi 2011 © 54

Page 55: Lecture-03 Introduction to UML

Constraints and Notes: Example

Al-Tamimi 2011 © 55

Page 56: Lecture-03 Introduction to UML

Constraints and Notes: Example

Al-Tamimi 2011 © 56

Page 57: Lecture-03 Introduction to UML

Resources

• Matt Weisfeld, The Object Oriented Thought Process, Sams Publishing, ISBN:0-672-32611-6

• M. Jesse, “UML 2.0 for dummies”, ISBN:0764526146

• P. Kimmel, “UML Demystified”, McGraw Hill, ISBN: 0-07-148671-2

• http://www.thefullwiki.org/Unified_Modeling_Language

57Al-Tamimi 2011 ©

Page 58: Lecture-03 Introduction to UML

Resources

• Object oriented technology, By Tsang, Lau & Leung 2005, Mcgraw-Hill

• M. Chonoles and J. Schardt, UML 2 for dummies, ISBN:0764526146

• http://publib.boulder.ibm.com/infocenter/rsmhelp/v7r0m0/index.jsp?topic=/com.ibm.xtools.modeler.doc/topics/cdepend.html

Al-Tamimi 2011 © 58


Recommended