4b use-case analysis

Preview:

DESCRIPTION

 

Citation preview

Use-Case Analysis

2

Topics Use-Case Analysis Overview Use-Case Analysis Steps

Supplement The Use-Case Description Find Classes From Use-Case Behavior Distribute Use-Case Behavior to Classes Describe Responsibilities Describe Attributes and Associations Unify Analysis Classes

Review

3

Objectives: Use-Case Analysis Identify the classes which perform a use-case flow

of events Distribute the use-case behavior to those classes,

identifying responsibilities of the classes Develop Use-Case Realizations that model the

collaborations between instances of the identified classes

4

Use-Case Analysis Overview

SupplementarySpecifications

Glossary

Use-Case Model

Use-CaseAnalysis

Project SpecificGuidelines

Use-Case Realization

Analysis Classes

Analysis Model

Software ArchitectureDocument

Use Case Analysis is performedBy the Designer – once per Iteration per use case realization

5

Use-Case Analysis Steps Supplement the Use-Case Description For each Use-Case Realization

Find Classes from Use-Case Behavior Distribute Use-Case Behavior to Classes

For each resulting analysis class Describe Responsibilities Describe Attributes and Associations Qualify Analysis Mechanisms

Unify Analysis Classes Checkpoints

6

Use-Case Analysis StepsSupplement the Use-Case Description For each Use-Case Realization

Find Classes from Use-Case Behavior Distribute Use-Case Behavior to Classes

For each resulting analysis class Describe Responsibilities Describe Attributes and Associations Qualify Analysis Mechanisms

Unify Analysis Classes Checkpoints

7

Supplement the Use-Case Description

8

Supplement the Use-Case Description For each Use-Case Realization

Find Classes from Use-Case Behavior Distribute Use-Case Behavior to Classes

For each resulting analysis class Describe Responsibilities Describe Attributes and Associations Qualify Analysis Mechanisms

Unify Analysis Classes Checkpoints

Use-Case Analysis Steps

9

Use-Case Realization

Class Diagrams

Sequence Diagrams

Use Case

Collaboration Diagrams

Use-Case Model Design Model

Use Case Use-Case Realization

10

Analysis Classes

Use Cases AnalysisClasses

SourceCode

ExecDesignElements

Use-Case Analysis

A First Step Toward Executables

11

Find Classes from Use-Case Behavior The complete behavior of a use case has to be

distributed to analysis classes

12

What Is an Analysis Class?

13

What Is a Boundary Class? Intermediates between the interface and

something outside the system Several Types

User interface classes System interface classes Device interface classes

One boundary class per actor/use-case pair

Environment Independent

14

The Role of a Boundary Class

Model interaction between the system and its environment

Customer

<<boundary>>

<<boundary>>

<<control>><<boundary>>

<<entity>> <<entity>>

External Database

15

Example: Finding Boundary Classes One boundary class per actor/use case pair

16

Guidelines: Boundary Class User Interface Classes

Concentrate on what information is presented to the user Do NOT concentrate on the UI details

System and Device Interface Classes Concentrate on what protocols must be defined Do NOT concentrate on how the protocols will be

implemented

Concentrate on the responsibilities, not the details!

17

What Is an Entity Class? Key abstractions of the system

Environment Independent

18

The Role of an Entity Class

Store and manage information in the system

19

Example: Finding Entity Classes

Use use-case flow of events as input Key abstractions of the use case Traditional, filtering nouns approach

Underline noun clauses in the use-case flow of events Remove redundant candidates Remove vague candidates Remove actors (out of scope) Remove implementation constructs Remove attributes (save for later) Remove operations

20

Example: Candidate Entity Classes Register for Courses (Create Schedule)

1. Hệ thống lấy danh sách học phần có mở trong học kỳ từ hệ thống Course Catalog System và thể hiện dưới dạng danh sách cho sinh viên chọn.

2. Sinh viên chọn 4 học phần bắt buộc và hai học phần tự chọn từ danh sách trên.

3. Sau khi sinh viên chọn, hệ thống tạo một lịch học chứa những học phần sinh viên đã đăng ký.

4. Sinh viên kiểm tra và xác nhận lịch học, Submit Schedule được thực thi.

21

What Is a Control Class? Use-case behavior coordinator

More complex use cases generally require one or more control classes

Use-case dependent, Environment independent

22

The Role of a Control Class

Coordinate the use-case behavior

23

Example: Finding Control Classes In general, identify one control class per use case.

As analysis continues, a complex use case’s control class may evolve into more than one class

24

Example: Summary: Analysis Classes

Use-Case Model

Design Model

Supplement the Use-Case Description For each Use-Case Realization

Find Classes from Use-Case BehaviorDistribute Use-Case Behavior to Classes

For each resulting analysis class Describe Responsibilities Describe Attributes and Associations Qualify Analysis Mechanisms

Unify Analysis Classes Checkpoints

25

Use-Case Analysis Steps

26

Distribute Use-Case Behavior to Classes For each use-case flow of events:

Identify analysis classes Allocate use-case responsibilities to analysis classes Model analysis class interactions in Interaction diagrams

27

Guidelines: Allocating Responsibilities to ClassesUse analysis class stereotypes as a guide Boundary Classes

Behavior that involves communication with an actor

Entity Classes Behavior that involves the data encapsulated within the

abstraction

Control Classes Behavior specific to a use case or part of a very important

flow of events

28

Allocating Responsibilities to Classes (cont.)

Who has the data needed to perform the responsibility?

If one class has the data, put the responsibility with the data

If multiple classes have the data: Put the responsibility with one class and add a relationship

to the other Create a new class, put the responsibility in the new class,

and add relationships to classes needed to perform the responsibility

Put the responsibility in the control class, and add relationships to classes needed to perform the responsibility

29

Objects Collaborate Objects are useless unless they can collaborate to

solve a problem. Each object is responsible for its own behavior and status. No one object can carry out every responsibility on its own.

How do objects interact with each other? They interact through messages.

30

Objects Interact with Messages A message shows how one object asks another

object to perform some activity.

: Car buyer:RegistrationController :CourseCatalogSystem

getCourseOfferings(forSemester)

Message

31

Interaction Diagrams Generic term that applies to several diagrams that

emphasize object interactions Sequence Diagram

Time oriented view of object interaction

Communication Diagram(or Collaboration Diagram) Structural view of messaging objects

Communication Diagrams

Sequence Diagrams

32

What Is a Sequence Diagram? A sequence diagram is an interaction diagram that

emphasizes the time ordering of messages. The diagram shows:

The objects participating in the interaction. The sequence of messages exchanged.

Sequence Diagram

33

Sequence Diagram Contents: Objects

Anonymous Objects

Lifelines

Named Object

:RegisterForCoursesForm :RegistrationController SWTSU Catalog : CourseCatalogSystem

34

Sequence Diagram Contents: Actor

:RegisterForCoursesForm :RegistrationController SWTSU Catalog : CourseCatalogSystem

: Student : Course Catalog

Actor instancesActor instances

35

Sequence Diagram Contents: Messages

MessageReflexiveMessages

1: create schedule( )

2: get course offerings( )

3: get course offerings(for Semester)

4: get course offerings( )

:RegisterForCoursesForm :RegistrationController SWTSU Catalog : CourseCatalogSystem

: Student : Course Catalog

6: display blank schedule( )

5: display course offerings( )

1: create schedule( )

4: get course offerings( )

36

Execution Occurrence (Focus of control)

1: create schedule( )

2: get course offerings( )

3: get course offerings(for Semester)

4: get course offerings( )

6: display blank schedule( )

:RegisterForCoursesForm :RegistrationController SWTSU Catalog : CourseCatalogSystem

: Student : Course Catalog

5: display course offerings( )

Execution Occurrence

37

Event Occurrence

Event Occurrence

1: create schedule( )

2: get course offerings( )

3: get course offerings(for Semester)

4: get course offerings( )

6: display blank schedule( )

:RegisterForCoursesForm :RegistrationController SWTSU Catalog : CourseCatalogSystem

: Student : Course Catalog

5: display course offerings( )

38

Register for Courses Use Case – Basic flow: Create a Schedule 1. The Student selects "create schedule."

2. The system retrieves a list of available course offerings from the Course Catalog System.

3. The system displays a blank schedule form.

4. The Student selects 4 primary course offerings and 2 alternate course offerings from the list of available offerings. Once the selections are complete the Student selects "submit."

5. Hệ thống tạo một lịch học chứa những học phần sinh viên đã đăng ký.

6. Sinh viên kiểm tra và xác nhận lịch học, Submit Schedule được thực thi.

39

Analysis Classes

40

Example: Sequence Diagram

: Student : RegisterForCoursesForm : RegistrationController : Schedule : Student : Course Catalog : CourseCatalogSystem

1: // create schedule( )

5: // display course offerings( )

2: // get course offerings( )

3: // get course offerings(forSemester)

A list of the available course offerings for this semester are displayed

Student wishes to create a new schedule

6: // display blank schedule( )

At this, point the Submit Schedule subflow is executed.

Sequence Diagram: Register for Courses / Register for Courses - Basic Flow (Submit Schedule)

7: // select 4 primary and 2 alternate offerings( )

8: // create schedule with offerings( )

A blank schedule is displayed for the students to select offerings

9: // create with offerings( )

10: // add schedule(Schedule)

4: // get course offerings( )

41

Use case: WithdrawActor: ClientBrief: To allow the client to withdraw moneyPre-conditions: User already logged-inPost-conditions: Amount is deducted from user’s accountMain flow:

1) Client initiates this usecase by selecting 'withdraw'2) System displays all the accounts related to the Card and

prompts to select any one.3) Client selects one account.4) System prompts for the amount (fast cash or …)5) Client enter amount …

Alternative flows:2) & 3) System selects the only one available account…

ClientUserAccountAmountMoneyCardCash

Identify Nouns

Example: Use case Withdraw of ATM

42

Analysis Classes

WithdrawUI WithdrawControl

Card Account

43

Sequence Diagram – Use case Withdraw

: Client : WithdrawUI : WithdrawControl : Card : Account

1: select withdraw

2: // get accounts(card)

3: // get accounts( )

4: // display accounts( )

5: select account

6: enter amount

7: // withdraw from(selected account, amount)

8: withdraw(amount )

44

Bài tập: Rent Video Use case: Basic flow1. Nhân viên dùng thiết bị quét thẻ thành viên của

khách hàng.2. Hệ thống kiểm tra băng đĩa video thuê quá hạn và

mức độ đáng tin của khách hàng.3. Nhân viên quét mã vạch của các video khách hàng

muốn thuê. Số lượng băng đĩa khách hàng thuê phải nhỏ hơn 8.

4. Nhân viên nhập ngày thuê và hạn trả cho từng bản ghi thuê video.

5. Hệ thống tính toán và hiển thị lệ phí thuê video.6. Sau khi khách hàng thanh toán, nhân viên in biên

nhận thuê video và chọn chức năng Save 7. Hệ thống cập nhật các bản ghi thuê video.

45

46

What Is a Communication Diagram? A communication diagram emphasizes the

organization of the objects that participate in an interaction.

The communication diagram shows: The objects participating in the interaction. Links between the objects. Messages passed between the objects.

Communication Diagrams

47

Example: Communication Diagram

: Student

: RegisterForCoursesForm

: RegistrationController : CourseCatalogSystem

5: display course offerings( )6: display blank schedule( )

: Course Catalog1: create schedule( )

2: get course offerings( )

3: get course offerings(forSemester)

4: get course offerings( )

48

Communication Diagrams: Objects

Objects

: RegisterForCoursesForm

: RegistrationController SWTSU Catalog : CourseCatalogSystem

49

Communication Diagram: Actors

: Student : Course Catalog

: RegisterForCoursesForm

: RegistrationController SWTSU Catalog : CourseCatalogSystem

Actors

50

Communication Diagram: Links and Messages

: Student

: RegisterForCoursesForm

: RegistrationController : CourseCatalogSystem

5: display course offerings( )

6: display blank schedule( )

: Course Catalog1: create schedule( )

2: get course offerings( )

3: get course offerings(forSemester)

4: get course offerings( )

Links

Messages

51

Example: Communication Diagram

: Student

: RegisterForCoursesForm

: RegistrationController

: Schedule : Student

: CourseCatalogSystem

5: // display course offerings( )6: // display blank schedule( )

: Course Catalog

1: // create schedule( )7: // select 4 primary and 2 alternate offerings( )

2: // get course offerings( )8: // create schedule with offerings( )

9: // create with offerings( )

3: // get course offerings(forSemester)

10: // add schedule(Schedule)

4: // get course offerings( )

52

One Interaction Diagram Is Not Good Enough

Semantically equivalent Can convert one diagram to the other without losing any

information

Model the dynamic aspects of a system Model a use-case scenario

Sequence and Communication Diagram Similarities

54

Communication

Diagrams Show relationships in

addition to interactions Better for visualizing

patterns of collaboration Better for visualizing all

of the effects on a given object

Easier to use for brainstorming sessions

Sequence Diagrams

Show the explicit sequence of messages

Better for visualizing overall flow

Better for real-time specifications and for complex scenarios

Communication vs. Sequence Diagrams

Supplement the Use-Case Description For each Use-Case Realization

Find Classes from Use-Case Behavior Distribute Use-Case Behavior to Classes

For each resulting analysis classDescribe Responsibilities Describe Attributes and Associations Qualify Analysis Mechanisms

Unify Analysis Classes Checkpoints

55

Use-Case Analysis Steps

56

Describe Responsibilities What are responsibilities? How do I find them?

// PerformResponsibility

:Client :Supplier

Supplier

// PerformResponsibility

Interaction Diagram

Class Diagram

Example: View of Participating Classes (VOPC) Class Diagram

RegisterForCoursesForm

// submit schedule()// display course offerings()// update schedule()// delete schedule()// confirm schedule deletion()// request schedule delete confirmation()// display schedule()// register for courses()// display possible operations()// save schedule()// create schedule()// select 4 primary and 2 alternate offerings()// display blank schedule()// update offering selections()

<<boundary>>

CourseCatalogSystem

// get course offerings()

<<boundary>>

RegistrationController

// get course offerings()// get current schedule()// delete current schedule()// submit schedule()// is registration open?()// save schedule()// create schedule with offerings()// update schedule with new selections()

<<control>>Student

// get tuition()// add schedule()// get schedule()// delete schedule()// has pre-requisites()

<<entity>>CourseOffering

// add student()// remove student()// close registration()// get number of students()// cancel()// still open?()// add professor()// close()// save()

<<entity>>

Schedule

// commit()// select alternate()// remove offering()// level()// cancel()// get cost()// delete()// submit()// save()// any conflicts?()// create with offerings()// update with new selections()

<<entity>>

Maintaining Consistency: What to Look For

In order of criticality Redundant responsibilities across classes Disjoint responsibilities within classes Class with one responsibility Class with no responsibilities Better distribution of behavior Class that interacts with many other classes

Supplement the Use-Case Description For each Use-Case Realization

Find Classes from Use-Case Behavior Distribute Use-Case Behavior to Classes

For each resulting analysis class Describe ResponsibilitiesDescribe Attributes and Associations Qualify Analysis Mechanisms

Unify Analysis Classes Checkpoints

59

Use-Case Analysis Steps

60

Finding Attributes Properties/characteristics of identified classes Information retained by identified classes “Nouns” that did not become classes

Information whose value is the important thing Information that is uniquely "owned” by an object Information that has no behavior

61

Finding Relationships

Relationship for every link!

Link

Association

CollaborationDiagram

ClassDiagram 0..*

Prime suppliers

0..*

Client Supplier

:Client :Supplier

Client Supplier

PerformResponsibility()

62

Example: What Associations Can You Find?

: CourseOffering

: RegistrationController

: Schedule

: Student

: PrimaryScheduleOfferingInfo

8: any conflicts?( )

: RegisterForCoursesForm

2: submit schedule( )

4: submit( )3: save( )

7: still open?( )9: add student(Schedule)

5: is selected?( )10: mark as enrolled in( )

6: has pre-requisites(CourseOffering)

1: submit schedule( )

: Student

63

Example: VOPC: Finding Relationships

RegisterForCoursesForm

CourseOfferingSchedule0..40..*

Student0..*1

RegistrationController11 1

0..1

0..1

0..1

<<entity>> <<entity>> <<entity>>

<<control>><<boundary>>

primaryCourses

currentSchedule

64

Refine Class Diagram Identify Components (Reusabile)

Aggregation and Composition Super-Sub classes

65

Review: What Is Aggregation? A special form of association that models a whole-

part relationship between an aggregate (the whole) and its parts “is a part-of” relationship

66

Association or Aggregation? If two objects are tightly bound by a whole-part

relationship The relationship is an aggregation.

If two objects are usually considered as independent, although they are often linked The relationship is an association.

When in doubt use association

67

Nhận diện AggregationBốn ngữ nghĩa có thể của Aggregation Sở hữu độc quyền (Exclusive Owns): Order has Order

Line Có sự phụ thuộc tồn tại (không có Order Line nếu không có Order) Không chia sẻ Là thuộc tính cố định (một Order Line không thể chuyển sang Order khác)

Sở hữu (Owns): Car has Tire Không chia sẻ Không là thuộc tính cố định (có thể chuyển tire sang một car khác)

Có (Has): Department has Student Không có sự phụ thuộc tồn tại, co thể chia sẻ.

Thành viên (Member): Meeting has Chairperson Không có đặc trưng gì đặc biệt ngoại trừ là tư cách thành viên

68

Composition and Aggregation Aggregation cơ bản là bất kỳ quan hệ whole–part

Ngữ nghĩa có thể rất mơ hồ Tương ứng với ngữ nghĩa "Has" và "Member". Một đối tượng thành phần (part) có thể thuộc nhiều hơn

một đối tượng bao gồm (whole)

Composition là Aggregation mạnh hơn Tại một thời điểm, mỗi đối tượng thành phần (part) chỉ có

thể thuộc chỉ một đối tượng bao gồm (whole). Có sự phụ thuộc tồn tại từ "part" vào "whole"

Khi đối tượng "whole" bị hủy thì các "part" cũng bị hủy Tương ứng với ngữ nghĩa "ExclusiveOwns" và "Owns"

69

Aggregation and Composition

Quan hệ m*n có thể chấp nhận

Quan hệ m*n không được phép

Các Student có thể trong nhiều CourseOffering.Nếu CourseOffering bị hủy, các Student không bị hủy!

Nếu Order bị xóa, các OrderLIne trong Order cũng bị xóa!

Order OrderLine

1..*1 1..*1

StudentCourseOffering

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

70

Review: What Is Generalization? A relationship among classes where one class

shares the structure and/or behavior of one or more classes.

Defines a hierarchy of abstractions where a subclass inherits from one or more superclasses. Single inheritance Multiple inheritance

Is an “is a kind of” relationship.

71

Example: Single Inheritance One class inherits from another.

CheckingSavings

Superclass (parent)

Subclasses(children)

Generalization Relationship

Descendents

Ancestor

Account

- balance- name- number

+ withdraw()+ createStatement()

72

Example: Multiple Inheritance A class can inherit from several other classes.

Use multiple inheritance only when needed and always with caution!

FlyingThing Animal

HorseWolfBirdHelicopterAirplane

Multiple Inheritance

Supplement the Use-Case Description For each Use-Case Realization

Find Classes from Use-Case Behavior Distribute Use-Case Behavior to Classes

For each resulting analysis class Describe Responsibilities Describe Attributes and AssociationsQualify Analysis Mechanisms

Unify Analysis Classes Checkpoints

73

Use-Case Analysis Steps

74

Review: Why Use Analysis Mechanisms?

Analysis mechanisms are used during analysis to reduce the complexity of analysis, and to improve its consistency by providing designers with a shorthand representation for complex behavior.

75

Describing Analysis Mechanisms Collect all analysis mechanisms in a list Draw a map of the client classes to the analysis

mechanisms Identify characteristics of the analysis mechanisms

76

Example: Describing Analysis Mechanisms Analysis class to analysis mechanism map

Analysis Class Analysis Mechanism(s)

Student Persistency, Security

Schedule Persistency, Security

CourseOffering Persistency, Legacy Interface

Course Persistency, Legacy Interface

RegistrationController Distribution

77

Analysis mechanism characteristics Persistency for Schedule class:

Granularity: 1 to 10 Kbytes per product Volume: up to 2,000 schedules Access frequency

Create: 500 per day Read: 2,000 access per hour Update: 1,000 per day Delete: 50 per day

Other characteristics

Example: Describing Analysis Mechanisms

78

Supplement the Use-Case Description For each Use-Case Realization

Find Classes from Use-Case Behavior Distribute Use-Case Behavior to Classes

For each resulting analysis class Describe Responsibilities Describe Attributes and Associations Qualify Analysis Mechanisms

Unify Analysis Classes Checkpoints

Use-Case Analysis Steps

79

Unify Analysis Classes

80

Evaluate Your Results

81

Use-Case Analysis Steps Supplement the Use-Case Description For each Use-Case Realization

Find Classes from Use-Case Behavior Distribute Use-Case Behavior to Classes

For each resulting analysis class Describe Responsibilities Describe Attributes and Associations Qualify Analysis Mechanisms

Unify Analysis ClassesCheckpoints

82

Are the classes reasonable? Does the name of each class clearly

reflect the role it plays? Does the class represent a single

well-defined abstraction? Are all attributes and responsibilities functionally

coupled? Does the class offer the required behavior? Are all specific requirements on the class

addressed?

Checkpoints: Analysis Classes

83

Have all the main and/or sub-flowsbeen handled, including exceptional cases?

Have all the required objects been found?

Has all behavior been unambiguously distributed to the participating objects?

Has behavior been distributed to the right objects?

Where there are several Interaction diagrams, are their relationships clear and consistent?

Checkpoints: Use-Case Realizations

84

Review: Use-Case Analysis What is the purpose of Use-Case Analysis? What is an analysis class? Name and describe the

three analysis stereotypes. What is a Use-Case Realization? Describe some considerations when allocating

responsibilities to analysis classes. How many Interaction diagrams should be

produced during Use-Case Analysis?

85

Exercise: Use-Case Analysis Given the following: Use-Case Model, especially the use-case flows of

events Key abstractions/classes The Supplementary Specification The possible analysis mechanisms

86

Exercise: Use-Case Analysis (cont.) Identify the following for a particular use case: The analysis classes, along with their:

Brief descriptions Stereotypes Responsibilities

The collaborations needed to implement the use case

Analysis class attributes and relationships Analysis class analysis mechanisms

87

Exercise: Use-Case Analysis (cont.) Produce the following for a particular use case: Use-Case Realization Interaction diagram for at

least one of the usecase flows of events VOPC class diagram, containing the analysis

classes, their stereotypes, responsibilities, attributes, and relationships

Analysis class to analysis mechanism map

88

Exercise: Use-Case Analysis (cont.) Start with diagramming the basic flow and then do the

other sub-flows if you have time. The Interaction diagrams may be collaboration or

Sequence diagrams. On an Interaction diagram, sending a message to an object means that you are allocating responsibility for performing that task to the object.

Be sure to use the “//” naming convention for responsibilities.

Refer to the following slides if needed: Review: What is a Use-Case Realization Example: Sequence Diagram Example: Collaboration Diagram Example: VOPC Finding Relationship