Introduction to UML C++ Object Oriented Programming Pei-yih Ting - - PowerPoint PPT Presentation

introduction to uml
SMART_READER_LITE
LIVE PREVIEW

Introduction to UML C++ Object Oriented Programming Pei-yih Ting - - PowerPoint PPT Presentation

Introduction to UML C++ Object Oriented Programming Pei-yih Ting NTOU CS 1 Contents Software modeling What is UML? What is UML for? UML history UML artifacts: Things, Relationships, and Diagrams Things Relationships


slide-1
SLIDE 1

1

Introduction to UML

C++ Object Oriented Programming Pei-yih Ting NTOU CS

slide-2
SLIDE 2

2

Contents

 Software modeling  What is UML? What is UML for?  UML history  UML artifacts: Things, Relationships, and Diagrams  Things  Relationships  Diagrams  A simple example  An elaborated example

slide-3
SLIDE 3

3

Introduction to Modeling

 The models we choose have a profound influence

  • n the solution we provide

 Every model may be expressed at different levels

  • f abstraction

 The best models are connected to reality  No single model is sufficient, a set of models is

needed to solve any nontrivial system

slide-4
SLIDE 4

4

Importance of Modeling

 Why do we model?  A model is a simplification at some level of

abstraction

 We build models to better understand the systems

we are developing

 To help us visualize  To specify structure or behavior  To provide template for building system  To document decisions we have made

slide-5
SLIDE 5

5

Software Modeling

 Traditionally two approaches to modeling a

software system

 Algorithmically – becomes hard to focus on as the

requirements change

 Object-oriented – models more closely real world

entities

slide-6
SLIDE 6

6

UML is a visual modeling language

 “A picture is worth a thousand words.” - old saying

 United Modeling Language:

“A language provides a vocabulary and the rules for combining words […] for the purpose of communication. A modeling language is a language whose vocabulary and rules focus on the conceptual and physical representation

  • f a system. A modeling language such as the UML is thus

a standard language for software blueprints.”

 from ”UML user guide”

slide-7
SLIDE 7

7

Software Invisibility

 Brooks in his famous article ‘No Silver Bullet-Essence

and Accidents of Software Engineering’: “invisibility is an inherent, not accidental, property of software”

 The multi-dimensional nature of software does not easily

lend itself to a single 2D or 3D diagrammatic form and thereby deprives us one of our most powerful conceptual tools: Our visual and spatial perception.

slide-8
SLIDE 8

8

UML History

 UML: Unified Modeling Language

 Grady Booch: Booch notation 1994

 language design, focus on structural aspects esp. inheritance

 James Rumbaugh et al.: OMT 1991

 background in database and Entity Relation modeling

 Evar Jacobson: OOSE 1992

 use cases / requirements

 The Three Amigos joined in 1997

 unified means ”joint effort instead of wars”

slide-9
SLIDE 9

9

Usages of UML

 UML is used in the course to

 document designs  design patterns / frameworks  represent different views/aspects of design – visualize and

construct designs

 static / dynamic / deployment / modular aspects  provide a next-to-precise, common, language – specify visually  for the benefit of analysis, discussion, comprehension…  abstraction takes precedence over precision!  aim is overview and comprehension; not execution

slide-10
SLIDE 10

10

Building Blocks of UML

 Things  Relationships  Diagrams

slide-11
SLIDE 11

11

Things

 Structural things

 classes, interfaces, collaborations, use cases, active

classes, components, nodes.

 Behavioral things

 interactions, finite state machines.

 Grouping things

 packages.

 Annotational things

 notes.

slide-12
SLIDE 12

12

Relationships

 Dependency  Association  Generalization  Realization

slide-13
SLIDE 13

13

Diagrams

  • 1. Class diagram
  • 2. Object diagram
  • 3. Use case diagram
  • 4. Sequence diagram
  • 5. Collaboration diagram
  • 6. Statechart diagram
  • 7. Activity diagram
  • 8. Component diagram
  • 9. Deployment diagram
slide-14
SLIDE 14

14

Structural Things

 Structural things are the nouns of UML models.

These are the mostly static parts of a model, representing elements that are either conceptual or physical.

slide-15
SLIDE 15

15

Structural Things (cont’d)

 Class

A description of a set of objects that share the same attributes, operations, relationships, and semantics

 Attribute

 An attribute is a named property of a class that describes a

range of values that instances of the property may hold.

 Operation

 An operation is the implementation of a service that can be

requested from any object to affect behavior.

slide-16
SLIDE 16

16

Class Diagram

Battery 5V Switch Resistor Light Structure of system (objects, attributes, associations, operations)

slide-17
SLIDE 17

17

Structural Things (cont’d)

 Use case

specifies the behavior of a system or a part of a system and is a description of a set of sequences of actions, including variants, that a system performs to yield an observable result of value to an actor

 Actor

An actor represents a coherent set of roles that users of use cases play when interacting with these use cases.

slide-18
SLIDE 18

18

Use Case Diagram

SimpleCircuit FlipOn FlipOff ViewLight User Functionality from user’s point of view

slide-19
SLIDE 19

19

Structural Things (cont’d)

 Interface

a collection of operations that specify a service of a class or component

 Collaboration

A collaboration defines an interaction and is a society of roles and other elements that work together to provide some cooperative behavior that's bigger than the sum of all the elements.

slide-20
SLIDE 20

20

Structural Things (cont’d)

 Active class

An active class is a class whose objects own one or more processes or threads and therefore can initiate control activity.

 Component

A component is a physical and replaceable part of a system that conforms to and provides the realization

  • f a set of interfaces.

 Node

A node is a physical element that exists at run time and represents a computational resource.

slide-21
SLIDE 21

21

Behavioral Things

Behavioral things are the dynamic parts of UML models. These are the verbs of a model, representing behavior over time and space.

 Interaction

An interaction is a behavior that comprises a set of messages exchanged among a set of objects within a particular context to accomplish a specific purpose.

 State machine

A state machine is a behavior that specifies the sequences of states an object or an interaction goes through during its lifetime in response to events, together with its response to those events.

slide-22
SLIDE 22

22

Interaction Diagram: Sequence Diagram

Resistor Switch Battery Light Messages between objects User

FlipOn() HeatUp() Drain() Shine()

slide-23
SLIDE 23

23

Statechart Diagram (different objects)

Cold Hot flipSwitchOn flipSwitchOff

Not Draining Draining

flipSwitchOn flipSwitchOff (Resistor) (Battery)

slide-24
SLIDE 24

24

Grouping and Annotational Things

Grouping things are the organizational parts of UML models.

 Package

A package is a general purpose mechanism for

  • rganizing elements into groups.

Annotational things are the explanatory parts of UML models.

 Note

A note is simply a symbol for rendering constraints and comments attached to an element or a collection of elements.

slide-25
SLIDE 25

25

Component Diagram

Course Course Offering Student Professor Course.dll People.dll

Course User Register.exe Billing.exe Billing System

class packaging and dependencies

slide-26
SLIDE 26

26

Relationships

 Dependency

A dependency is a using relationship that states that a change in specification of one thing may affect another thing that uses it, but not necessarily the

  • reverse. (Usually a class depends on some interfaces
  • r abstract classes instead of another class.)

 Association

An association is a structural relationship that specifies that objects of one thing are connected to

  • bjects of another.
slide-27
SLIDE 27

27

Relationships (cont’d)

 Aggregation

An aggregation is a special form of association that specifies a whole-part relationship between the aggregate (the whole) and a component (the part).

 Generalization

A generalization is a relationship between a general thing and a more specific kind of that thing. Sometimes it is called an “is-a-kind-of” relationship.

 Realization

A realization is a semantic relationship between classifiers, wherein, one classifier specifies a contract (interface) that another classifier promises to carry out.

slide-28
SLIDE 28

28

Diagrams

 Class diagram

A class diagram shows a set of classes, interfaces, and collaborations and their relationships.

 Object diagram

An object diagram shows a set of objects and their relationships.

 Use case diagram

A use case diagram shows a set of use cases and actors and their relationships. A Use case is a literary form of describing user goals, as a set of scenarios. A scenario is a sequence of steps describing interaction between a user and a system.

slide-29
SLIDE 29

29

Diagrams (cont’d)

 Sequence diagram

A sequence diagram is an interaction diagram that emphasizes the time-ordering of messages.

 Collaboration diagram

A collaboration diagram is an interaction diagram that emphasizes the structural organization of the

  • bjects that send and receive messages.

 Statechart diagram

A statechart diagram shows a state machine, consisting of states, transitions, events, and activities.

slide-30
SLIDE 30

30

Diagrams (cont’d)

 Activity diagram

An activity diagram is a special kind of a statechart diagram that shows the flow from activity to activity within a system.

 Component diagram

A component diagram shows the organization and dependencies among a set of components.

 Deployment diagram

A deployment diagram shows the configuration of runtime processing nodes and the components that live on them.

slide-31
SLIDE 31

31

Class Diagrams

 Same diagram – different perspectives

 Conceptual

 focus: domain modeling  “software independent” – no software specific parts

 Specification

 focus: responsibilities and contracts/interfaces  we are talking software i.e. we include software related

aspects: design patterns, frameworks, etc.

 Implementation

 close mapping to actual source code

slide-32
SLIDE 32

32

Contracts and Responsibility

 Classes are too close to implementation.

 Instead think in terms of contracts and responsibility!  UML (and java) approximation is interfaces

InputStream

{abstract}

DataInputStream

<<interface>>

DataInput OrderReader realization dependency generalization

slide-33
SLIDE 33

33

A Simple Problem

1  5 V light switch

slide-34
SLIDE 34

34

Use Case Diagram

SimpleCircuit FlipOn FlipOff ViewLight User Functionality from user’s point of view

slide-35
SLIDE 35

35

Class Diagram

Battery 5V Switch Resistor Light Structure of system (objects, attributes, associations, operations)

slide-36
SLIDE 36

36

Interaction Diagram: Sequence Diagram

Resistor Switch Battery Light Messages between objects User

FlipOn() HeatUp() Drain() Shine()

slide-37
SLIDE 37

37

Interaction Diagram: Collaboration Diagram

Resistor Alternative to sequence diagram, More compact, but harder to interpret User

  • 1. FlipOn()

1.1 HeatUp() 1.3 Drain() 1.2 Shine()

Battery Switch Light sequence number

slide-38
SLIDE 38

38

Statechart Diagram

Transitions between states of an object (Extension of Finite State Machine (FSM) model) Light Off Light On flipSwitchOn flipSwitchOff

slide-39
SLIDE 39

39

Statechart Diagram (different objects)

Cold Hot flipSwitchOn flipSwitchOff

Not Draining Draining

flipSwitchOn flipSwitchOff (Resistor) (Battery)

slide-40
SLIDE 40

40

Activity Diagram

  • Actions are states
  • shows the flow from activity to activity within a system

Flip Switch On Flip Switch Off

slide-41
SLIDE 41

41

More Elaborated Example

 The ESU University wants to computerize their

registration system

 The Registrar sets up the curriculum for a semester

 One course may have multiple course offerings

 Students select 4 primary courses and 2 alternate courses  Once a student registers for a semester, the billing system

is notified so the student may be billed for the semester

 Students may use the system to add/drop courses for a

period of time after registration

 Professors use the system to receive their course offering

rosters

 Users of the registration system are assigned passwords

which are used at logon validation

slide-42
SLIDE 42

42

Actors

 An actor is someone or some thing that must

interact with the system under development

Student Registrar Professor Billing System

slide-43
SLIDE 43

43

Use Cases

 use case is a pattern of behavior the system exhibits

 Each use case is a sequence of related transactions

performed by an actor and the system in a dialogue

 Actors are examined to determine their needs

 Registrar -- maintain the curriculum  Professor -- request roster  Student -- maintain schedule  Billing System -- receive billing information from

registration

Maintain Schedule Maintain Curriculum Request Course Roster

slide-44
SLIDE 44

44

Use Case Diagram

Student Professor Maintain Schedule Maintain Curriculum Request Course Roster Billing System

Registrar

slide-45
SLIDE 45

45

Sequence Diagram

: Student registration form registration manager math 101

1: fill in info 2: submit 3: add course (joe, math 101) 4: are you open? 5: are you open? 6: add (joe) 7: add (joe)

math 101 section 1

slide-46
SLIDE 46

46

Collaboration Diagram

: Registrar course form : CourseForm theManager : CurriculumManager aCourse : Course 1: set course info 2: process 3: add course 4: new course

slide-47
SLIDE 47

47

Classes

RegistrationForm RegistrationManager Course Student CourseOffering Professor ScheduleAlgorithm

slide-48
SLIDE 48

48

Classes: Attributes and Operations

RegistrationForm Student ScheduleAlgorithm RegistrationManager

addStudent(Course, StudentInfo) name major

Professor

name tenureStatus

Course

name numberCredits

  • pen()

addStudent(StudentInfo)

CourseOffering

location

  • pen()

addStudent(StudentInfo)

slide-49
SLIDE 49

49

Relationships

RegistrationForm RegistrationManager

addStudent(Course, StudentInfo)

Course

name numberCredits

  • pen()

addStudent(StudentInfo)

Student

name major

CourseOffering

location

  • pen()

addStudent(StudentInfo)

Professor

name tenureStatus

ScheduleAlgorithm

slide-50
SLIDE 50

50

Multiplicity and Navigation

1 0..* 0..* 1 1 1..* 4 3..10 0..4 1

RegistrationForm RegistrationManager

addStudent(Course, StudentInfo)

Course

name numberCredits

  • pen()

addStudent(StudentInfo)

Student

name major

CourseOffering

location

  • pen()

addStudent(StudentInfo)

Professor

name tenureStatus

ScheduleAlgorithm

  • ffered

Courses

Role name

slide-51
SLIDE 51

51

Inheritance

name

RegistrationUser RegistrationForm RegistrationManager

addStudent(Course, StudentInfo)

Course

name numberCredits

  • pen()

addStudent(StudentInfo)

Student

major

CourseOffering

location

  • pen()

addStudent(StudentInfo)

Professor

tenureStatus

ScheduleAlgorithm

slide-52
SLIDE 52

52

State Transition Diagram

Initialization Open

entry: Register student exit: Increment count

Closed Canceled

do: Initialize course do: Finalize course do: Notify registered students

Add Student / Set count = 0 Add student [ count < 10 ] [ count = 10 ] Cancel Cancel Cancel

slide-53
SLIDE 53

53

Component Diagram

Course Course Offering Student Professor Course.dll People.dll

Course User Register.exe Billing.exe Billing System

class packaging and dependencies

slide-54
SLIDE 54

54

Deployment Diagram

Registration Database Library Dorm Main Building

physical setup

slide-55
SLIDE 55

55

More Graphical Notations

 Class Diagram: abstract, static

abstract class ParentClass { int field; static char field2; abstract void methodA(); double methodB() { … } } class ChildClass extends ParentClass { void methodA() { … } static void methodC() { … } }

ParentClass field1 field2 methodA methodB ChildClass methodA methodC

slide-56
SLIDE 56

56

More Graphical Notations

 Access Control

class SomeClass { private int privateField; protected int protectedField; public int publicField; private void privateMethod() { } protected void protectedMethod() { } public void publicMethod() { } }

SomeClass

  • privateField

# protectedField + publicField

  • privateMethod

# protectedMethod + publicMethod

slide-57
SLIDE 57

57

More Graphical Notations

 Sequence diagram: message, return, lifeline, activation

class Server { Device device; void open() { … } void print(String s) { device.write(s); … } void close() { … } … } class Client { Server server; void work() { server.open(); server.print("Hello"); server.close(); } … } class Device { void write(String s) { … } }

:Client :Server :Device

work

  • pen

print close write

slide-58
SLIDE 58

58

References

a. UML Distilled, Applying the Standard Object Modeling Language, Martin Fowler, (UML 精華:應用標準物件模式語言, 許銀雄譯, AW/松崗)

  • b. 物件導向系統分析與設計, 使用 UML 與 C++, 周斯畏編著, 全

華, 92/05, 九十年度非同步遠距教學 c. UML 理論與實作 --- 個案討論與經驗分享, 張裕益著, 博碩, 91/02

  • d. UML 使用手冊, 張裕益譯, 博碩, 90/10