www.isbe.tue.nl UML Use Case Modeling: Use Case Diagram / Use Case Description 6 January 2016 7M900 www.isbe.tue.nl Use Case Approach library system Provide lending services Library user Control user administration Books database Library staff 2 7M900 1 www.isbe.tue.nl Use Case Modeling • Use Case model – A model that describes the functional requirements of a system in terms of use cases. • A use case model partitions system functionality into – requirements / goals / transactions (‘use cases’) that are – meaningful to users (‘actors’); and is shown on a use case diagram • System developers and customers/end-users discuss a use case model. {In an iterative process, this lead to a requirement specification on which all agree.} 3 7M900 www.isbe.tue.nl UML Views vocabulary functionality system assembly configuration management Component view Design view Use Case view behaviour performance scalability throughput Concurrency view logical Deployment view physical system topology distribution delivery installation 4 7M900 2 www.isbe.tue.nl Use Case Diagram Definition A diagram that shows a set of use cases and actors and their relationships. Use cases represent system functionality, the requirement of the system from the user’s perspective. 5 7M900 www.isbe.tue.nl Use Case Definition • Fowler: – A use case is a typical interaction that a user has with a system in order to achieve some goals. – A use case is a description of a set of sequence of actions, including variants, that a system performs to yield an observable result of value to an actor. • Cockburn: – A use case describes a system’s behavior. 6 7M900 3 www.isbe.tue.nl Use Case • • • A use-case is a set of sequences of actions a system performs that yield an observable result of value to a particular actor. A use-case describes a requirement for the system, that is, what it should do, but not how it should do it. UseCaseName A use-case is a set of scenarios tied together by a common user goal. 7 7M900 www.isbe.tue.nl Actor 1of2 • An actor is someone or something that interacts with the system. It is who or what uses the system. – Could be human beings, other systems, timers, hardware devices, etc. • • Actors that stimulate the system are the initiators of events are called primary actors (active); Actors that only receive stimuli from the system are called secondary actors (passive). ActorName An actor is a role that a user plays with respect to the system. 8 7M900 4 www.isbe.tue.nl Actor 2of2 • An actor communicates with the system by sending and receiving messages. – Who/ what will be interested in the system? – Who/what will want to change or interface with the system? – Who/want information from the system? ActorName 9 7M900 www.isbe.tue.nl System Boundary • Represents the boundary between the (physical) system and the actors who interact with the (physical) system. 10 7M900 5 www.isbe.tue.nl Use Case Diagram A diagram that shows the relationships among actors and use cases within a system. Financial Trading System Set Limits Update Accounting Accounting System Analyze Risk <<include>> Price Deal <<include>> Trading Manager Value Deal Capture Deal Trader Salesperson 11 7M900 www.isbe.tue.nl Include (Uses) Relationship • Include : this relationship is used when there is a common chunk of behaviour across more than one use case. • Primary use case includes the functionality of included use case. 12 7M900 6 www.isbe.tue.nl Use Case Relationships <<extend>> Place Order <<include>> Supply Customer Data <<include>> Request Catalog <<include>> Order Product Arrange Payment generalization These use cases are varieties of Arrange Payment Cash Payment Credit Payment 13 7M900 www.isbe.tue.nl Generalization Relationship • Generalization is used when there is one use case similar to another. • Inheriting parent behaviour, adding and overriding with the child’s behaviour. • Sub use case inherits behaviour and semantics from super use cases. 14 7M900 7 www.isbe.tue.nl Use Case Relationships <<extend>> Place Order <<include>> Supply Customer Data <<include>> Request Catalog <<include>> Order Product Arrange Payment generalization These use cases are varieties of Arrange Payment Cash Payment Credit Payment 15 7M900 www.isbe.tue.nl Use Case Relationships condition: {user request catalog} extension point: more requests Place Order ___________ Place Order more requests <<include>> Supply Customer Data <<include>> <<extend>> Request Catalog <<include>> Order Product Arrange Payment generalization These use cases are varieties of Arrange Payment Cash Payment Credit Payment 16 7M900 8 www.isbe.tue.nl Extend Relationship • Extend is used to add behaviour to the primary use case at certain extension points. • A use case is optionally extended by functionality of another use case. 17 7M900 www.isbe.tue.nl Use Case Diagram Guidelines • Use cases should ideally begin with a verb – i.e. “Generate report”. Use cases should not be open ended. • Avoid showing communication between actors, and actors should be named singular. • Use case diagrams does not show sequence. • Generally the use of include and extend is discouraged because they add unnecessary complexity to a use diagram. • Since the primary purpose of use cases is to show user centered functionality, the precedence of use cases is less important. 18 7M900 9 www.isbe.tue.nl D2D example • D2D is a commercial online dating service • Requirements – Interest – Subscribe • Request for a subscription • Cancel a subscription – Profiles • Inspect a profile • Modify a profile – Messages – News 19 7M900 www.isbe.tue.nl D2D Example • D2D is a commercial online dating service • Requirements – Interest – Subscribe • Request for a subscription • Cancel a subscription D2D Request for subscription Visitor Inspect profile – Profiles • Inspect a profile • Modify a profile – Messages – News Modify profile Subscriber Cancel subscription 20 7M900 10 www.isbe.tue.nl Primary Use Cases : Examples Request for subscription Visitor Visitor Modify profile Inspect profile Subscriber Subscriber 21 7M900 www.isbe.tue.nl Separation • If there are many requirements (also called processes in this stadium); a requirement can be managed separately. • In the case of D2D Profiles: – Inspect a profile • Look for a profile • Consult a profile – Modify a profile 22 7M900 11 www.isbe.tue.nl Secondary Use Cases : An Example Use cases that supports the use case request for a subscription 23 7M900 www.isbe.tue.nl Secondary Use Cases : An Example Use cases that supports the use case request for a subscription – – – – – Import a subscription Validate a subscription Import credit card Validate credit card Mail confirmation by e-mail 24 7M900 12 www.isbe.tue.nl Secondary Use Cases : An Example {uses include / extend relationships} D2D Import subscription Request for subscription Validate subscription <<include>> <<include>> Visitor Inspect profile Request for subscription <<include>> <<include>> Modify profile Visitor Validate creditcard <<extend>> Subscriber Import creditcard Cancel subscription Mail confirmation 25 7M900 www.isbe.tue.nl Secondary Use Cases : An Example {uses generalization relationships} Renew subscription <<include>> Pay subscription D2D Pay subscription with Creditcard Pay subscription via Collection Pay subscription via Account 26 7M900 13 www.isbe.tue.nl Use Case Diagram – secondary actor Import subscription <<include>> <<include>> Request for subscription Visitor <<include>> Validate subscription Import creditcard <<include>> <<extend>> Validate creditcard Credit card company Mail confirmation 27 7M900 www.isbe.tue.nl Question? Timer Which use case is not valid? 28 7M900 14 www.isbe.tue.nl Question? Originating from UML SIG – UML Lecture series; APIIT Asia Pacific Institute of Information Technology What’s wrong? 29 7M900 www.isbe.tue.nl Question? WHY? 30 7M900 15 www.isbe.tue.nl Use Case Description1of2 A use case can be described by a use case text (also called use case specification), including the next characteristics: – – – – Name: the name of the use case concisely Actors: the involved actors Precondition: condition of the system at the start of the use case Stepwise description (flow of events / pathway): interaction between system and actor(s) – Exception: exceptional cases – Result: post condition of the system 31 7M900 www.isbe.tue.nl Use Case Description2of2 A use case description serves as a bridge between stakeholders of a system and the development team. Systems analyst produce use case diagram & use case text in consultation with end users Use Case Diagram Derived from UML SIG – UML Lecture series; APIIT Asia Pacific Institute of Information Technology Use Case Specification Programmers look at uses case text to understand complete requirements 32 7M900 16 www.isbe.tue.nl Use Case Text example from Inspect a profile Look for profile Inspect preferences <<include>> Subscriber <<extend>> Inspect profile <<extend>> Inspect photo <<extend>> Mail message Visitor 33 7M900 www.isbe.tue.nl Use Case Text example from Inspect a profile Use case ‘mail a message’ • • • • Name mail a message Actors subscriber Precondition profile is known, actor is logged in Description 1. get the profile 2. show web page 3. actor types in a new message 4. actor confirms mailing the message 5. application (d2d) sends message to profile 6. actor receives confirmation of sending a message • Result message mailed to profile; or actor has canceled 34 7M900 17 www.isbe.tue.nl Scenario A scenario is a sequence of steps describing an interaction between a user and a system. – A scenario is an instance of a use-case. – A scenario describes a possible interaction with the system. 35 7M900 www.isbe.tue.nl Scenario for use case ‘log in subscriber’ Description Chosen scenario 1. 2. 3. 4. 5. 6. 7. Number of valid logins < 3. Show web page. Actor types in login name and password. Actor confirms. Login is valid. Mark actor as subscriber. 8. Validate number of invalid logins . If number of invalid logins more than 2, stop. Show web page. Actor types in login name and password. Actor confirms. Application validates login. If login valid 7.1 mark actor as subscriber. If login invalid 8.1 raise the number of invalid logins. 8.2 repeat from step 1. 36 7M900 18 www.isbe.tue.nl Scenario example 1 of 2 • Consider a Web-based on-line store, we might have a ‘Buy a Product’ scenario that would say this : – The customer browses the catalogue and adds desired items to the shopping basket. – When the customer describes the shipping and credit card information and confirms the sale. – The system checks the authorization on the credit card and confirms he sale both immediately and with a follow-up mail. 37 7M900 www.isbe.tue.nl Scenario example 2 of 2 Buy a Product Main Success Scenario: 1. 2. 3. 4. 5. 6. 7. 8. Customer browses through catalog and selects items to buy Customer goes to check out Customer fills in shipping information (address; next-day or 3-day delivery) System presents full pricing information, including shipping Customer fills in credit card information System authorizes purchase System confirms sale immediately System sends confirming email to customer Extensions: 3a: Customer is regular customer 3a1: System displays current shipping, pricing, and billing information 3a2: Customer may accept or override those defaults, returns to MSS at step 6 6a: System fails to authorize credit purchase 6a1: Customer may re-enter credit card information or may cancel 38 7M900 19 www.isbe.tue.nl Template of use case text Name Name used to refer to a use case. Actors All actors involved. Preconditions Condition of the system at the start of the use case. Description A complete stepwise description of the interaction between system and actor(s). Extensions Lists the extension points currently defined for this selected Use Case. Exceptions Special and/or unexpected exceptional cases. Result Condition of the system at the end of the use case. 39 7M900 www.isbe.tue.nl NS Ticket machine – a use case approach Destination Purchase Ticket Traveler Maintenance basic data Take ticket NS 40 7M900 20 www.isbe.tue.nl NS Ticket machine – use case diagram Buy OV ticket <<extend>> <<include>> Buy NS ticket Traveler Pay ticket 41 7M900 www.isbe.tue.nl NS Ticket machine – use case text Use Case Buy OV Ticket Actors Traveller Preconditions Traveller has a valid pass Description 1. 2. 3. 4. 5. 6. 7. Ticket device expects destination code Traveller enters destination code Extension point: NS ticket Ticket device checks code and calculates the charge. Shows destination code & fare. Activates ticket machine for paying Traveller pays (use case: Pay ticket) Ticket device print and supplies ticket Traveller takes ticket Extension Destination code = NS station. 3a. Ticket device expects ticket type 3b. Traveller enters Single/Return, Discount Y/N, Class Exceptions Traveller interrupt the interaction or walk away Traveller enters an incorrect destination code Payment is not finished off successful Result Traveller has ticket. (NS can look forward to the payment) 42 7M900 21 www.isbe.tue.nl Study matter • Martin Fowler UML distilled , 2nd / 3rd edition – UML beknopt Addison Wesley • Grady Booch, James Rumbaugh, Ivar Jacobson The Unified Modeling Language User Guide, 2nd edition Addison Wesley • Sander Hoogendoorn Pragmatisch modelleren met UML 2.0 Addison Wesley { some slides are based from here} 43 7M900 22