uml exercises
TRANSCRIPT
Exercises on basic UML
Paolo Ciancarini
Summary
• This is a set of exercises on writing and understanding the UML notations
• Some exercises have more than one correct answer
• Most of them are taken from the net
Diagrams covered • Use case diagrams • Class diagrams • Object diagrams • State diagrams • Activity diagrams • Sequence diagrams • Communication diagrams
Think about it!
On requirements
Which of these are functional requirements? a) Users of the library are either normal or staff b) A user can borrow a book c) A staff person can borrow a book d) The library contains one million books e) If a user asks a book that has been borrowed, her
request is inserted in a waiting list f) Staff has no priority in borrowing books
On requirements
Which of these are non-functional requirements? a) Pressing the switch the room gets lightened b) Pressing the switch the room gets lightened in less than
one second c) If the room is dark, pressing the switch it gets lightened d) The light in the room must be sufficient to read e) If someone is reading then the light must stay on f) After two minutes that the room is empty the light must
switch off
On requirements
Which of these are functional requirements? a) A person can enroll in a course b) Only 10 persons max can enroll to this course c) A student is a person d) A course is taught by a professor e) A professor is not a student f) Each course terminates with an exam g) Every exam produces a ranking of all participants
On requirements
Which of these are functional requirements? The Iphone a) can function as a camera b) has a camera with 2.0 megapixels with geotagging c) is a portable media player d) offers an Internet client e) renders a virtual keyboard by its multitouch screen f) is connected to a PC via a USB plug g) includes a digital compass in the 3GS model
On requirements • Based on the following statements from a domain expert on a project, which of the
following are requirements that must be extracted? "We get incomplete mortgage applications all the time. In those cases, we just hand them back to the customer with a handwritten note telling them what's missing. We have to log the application anyway, so we use the new mortgage screen to enter the customer information and assign a unique identifier to the file. In the past, we have entered the address in upper case. The identifier follows an industry standard format of bank number, customer account number, and the next available number for that customer all as one long number."
a) A note must be sent to the customer for incomplete mortgage applications, listing the missing items
b) A file must be established for every mortgage application at the time it is submitted, whether the application is complete or not
c) Addresses on mortgage applications must be entered as all capital letters
d) A unique mortgage number must be assigned to each mortgage file. This identifier must follow financial industry standard format
On requirements
Which requirement has the best form? • The system could be used to manage one or
more libraries • The system shall manage the lending of books • The system is initially either off or on • The system could have several users • The system goal should be to let users to borrow
books
On requirements and Use Cases
• A library is attended by readers who borrow books and staff who lend books. Both operations require user id and passwd for logging reasons
log
borrow
lend log
borrow
lend
<<Include>>
<<include>>
log borrow
lend
<<extend>>
<<extend>>
a) b)
c)
Inventory System In order to generate an invoice a clerk must log in. If a clerk is a first time user, one must have themselves registered. There should be an option for a user to register oneself within the login page. Any user can use the system to view products online. The option of login is also provided when a user views products online.
On Use Cases diagrams Draw a use case diagram for the scenario below:
On Use Case diagrams
Customer Service Clerk
Maintain Relationships
Order Clerk
Process Orders
CustomerMaintain Orders
SupplierMaintain Inventory
Packaging ClerkShi p Product
Bill ing Clerk
Generate Invoice
Accounting Syste m
Manager
Time
Decision Support
Which use case is not valid?
On Use Case diagrams Identify two errors
On Use Cases diagrams Which sentences are true for this diagram? a) There are seven actors b) There is one main actor c) There are 18 use cases d) There are 10 use cases e) DropSeminar includes Registrar f) PostOffice extends DistributeTranscripts
On Use Case diagrams
Which statements are true for an Actor? a) an actor is a role a user plays with respect to the
system b) an actor can be modeled as a class c) an actor generates events d) generalization is not applicable to actors e) an actor does not need to be human: a subsystem
or external system can be modelled as an actor This question has 3 correct answers.
On Use Cases diagrams Which of these are true? a) The diagram shows a data flow from one actor to another b) The diagram shows an inheritance relationship between two
actors c) The diagram shows an <<extend>> dependency between two
actors d) Manager can use the same use cases as a Staff and one or
more additional ones e) Staff can use the same use cases as a Manager and one or
more additional ones f) Only Manager actors exist, as Staff is an abstract actor.
On Use Cases diagrams
• Is this diagram correct?
• Is there anything missing or to add?
• Can you provide a narrative for the diagram?
On Use Cases diagrams When you have the final list of use cases, some questions to ask to find out if you have found them all are:
a) Is each functional requirement in at least one use case? b) Have I considered how each stakeholder will be using the system? c) Have I missed any technical terms that describes the system? d) What information will each stakeholder be providing for and
receiving from the system? e) Have I considered the maintenance issues? f) Have I broken the problem down into pieces that the system will
handle? g) What information will each external system be providing to the
system and receiving from the system? h) Have I identified all of the external systems with which the system
will need to interact?
Reading exercises • Read the UML class diagram • Pay attention to the multiplicity • Try to understand the relationship and
describe it in natural language
Veterinary System • Try to read & understand this UML diagram
Veterinary System • Read and understand this UML diagram
• 1 or more Pets associated with 1 PetOwner • Each pet has exactly one PetOwner
Computer System
Computer System
• 1 CPU associated with 0 or more Controllers • 1-4 DiskDrives associated with 1 SCSIController
• SCSIController is a (specialized) Controller
Library System
Library System
• 1 or more Book associated with 1 or more Pages • Patron & Shelf use (depend on) Books
Banking System
Banking System
• 1 Bank associated with 0 or more Accounts • Each Account is associated with exactly one bank
• Checking, Savings, and MoneyMarket are Accounts
Home Heating System
Home Heating System
• Room has 1 Thermostat • Each Thermostat is associated with 0 or more Heaters
• A Heather has exactly one Thermostat
• ElectricHeater is a specialized Heater
• AubeTH101D is a specialized Thermostat
Company
• Each employee works for one company (which can have 0 employees)
• Each AdministrativeAssistant has one or more supervisors (who can have 0 or more employees) • Each Company has exactly one BoardOfDirectors (and viceversa)
• Each Office is allocated to zero or more Employees (an Employee can have no office or at most one) • A Person is boardMember of 0 or more BoardOfDirectors (each BoardOfDirectors has from 3 to 8 Persons)
Printing System
Family
A woman can have as sons two twins?
On class diagrams
• A house may have any number of pets living in it
• The two possible types of pets that can live in a house are dogs and cats
• Each dog or cat has a name • An animal’s house is its one and only
home • You can ell an animal to make noise and it
will do its thing
Solution
On class diagrams
Given that having multiple spouses at the same time is prohibited, but it is allowed to have many spouses over time …
a) The diagram represents the concepts to be modeled and no changes are required
b) Use the <<history>> stereotype to show the history over time and snapshot in time constraint in the model.
c) Promote the “is married to” association to an association class called Marriage and break up the Many-to-Many association between Husband and Wife
d) Create a link attribute called “wedding date” and attach it to the association, rather than to either Class in the Association
e) Create a link attribute called “wedding date” and attach it to either husband or wife class
Husband Wife is married to
0..n 0..n
On class diagrams
Which sentences are coherent with this model? a) A company may employ 0 or 1 person b) A person may work for a single company c) A person has one employment d) A company has one employer that is a person e) A company may have zero employers
Person Company employer
* 0..1
Period
Employment
On class diagrams
This diagram says that objects:
a) Persons have a name b) Guitarists have a name c) Guitars have a name d) MusicPlayers have a
name
On class diagrams
This diagram describes a) a sequence b) a domain c) a system d) a use case e) a temporal behavior
On class diagrams
Which of the following aspects is not part of a design class diagram? a) Attributes with their types b) Operations with arguments and results c) Composition relationship d) Events and actions e) Visibility information f) Navigation information
On class diagrams Classify the following into generalization (G), association
(A), aggregation (AG), or composition (C): a) A country has a capital city b) A dining philosopher uses a fork c) A file is an ordinary file or a directory file d) Files contain records e) A class can have several attributes f) A relation can be association or generalization g) A polygon is composed of an ordered set of points h) A person uses a computer language on a project
On class diagrams The arrow between the two classes indicates: a) Inheritance b) Association c) Dependency d) Sending a message
On class diagrams
On class diagrams
On class diagrams
A visitor register is made of visitor entries
On class diagrams This diagram says that objects having a “main” method are a) Persons b) Guitarists c) Guitars d) MusicPlayers, when implemented by Guitarists
On class diagrams:
• Right or wrong? Student
- passedModules: list of Strings
Module - name:String - code:int
Module
- name: String
- code: int
prerequisites + equivalents
On class diagrams
• Right or wrong?
*
On class diagrams
Examine these two diagrams; true or false? a) The right diagram has more information b) The left diagram has more information c) They are equivalent, but the right one is simpler d) They are equivalent, but the left one is simpler
On class diagrams
This association could be translated in an interface like: a) class Order { public OrderLine getLineItems() ;
public void addLineItem(Number amount);!b) class Order { public OrderLine getLineItems() ;
public void addLineItem(OrderLine lineItem);!c) class Order { public OrderLine getLineItems
(Product aProduct) ; public void addLineItem(Number amount, Product aProduct);!
d) class Order { public Object getLineItems() ; public void addLineItem(OrderLine lineItem); !!
On class diagrams
Which of the following are illegal combinations of subtypes in the diagram? a) Female, Patient, Nurse b) Male, Physiotherapist c) Female, Patient d) Female, Doctor, Surgeon e) Patient, Doctor f) Male, Doctor, Nurse
On class diagrams
A benefit of using polymorphism is a reduction of: a) methods in the associated classes b) subclasses needed to accomplish the same
functionality c) case statements and conditionals d) coupling between classes in the system
On class diagrams Which sentences are true? a) CheckingAccount implements BankAccount b) CheckingAccount and SavingAccount are BankAccount c) CheckingAccount and SavingAccount are associated d) BankAccount is associated to CheckingAccount e) SavingAccount can processCheck f) CheckingAccount has a balance
On object diagrams
• This object diagram is instance of which class diagram(s)?
Car
Wheel
Engine Car
Wheel
Engine Car
Engine Wheel
On object diagrams
This object diagram a) Includes an anonymous object b) Includes a class c) Includes four instances d) Includes three instances
On object diagrams
Which diagrams are correct?
Person
:John
Person
Man
Person
:John
Person
Man
a) b) c) d)
On objects diagrams
Which one is a non valid instance of this model?
a) b)
d)
c)
On object diagrams
• Which is the class diagram which best corresponds to this object diagram?
Teacher Student assgnlab handinlab team
Teacher Student assgnlab handinlab team1 team2
Teacher Student assgnlab handinlab team1
team2 Teacher Student assgnlab handinlab
1 2
a)
b)
c)
d)
On state diagrams This state diagram a) Has a superstate “student” b) Has a superstate “undergraduate”
c) Has several final states d) Has several initial states e) Describes two objects: student
and undergraduate
On state diagrams • Describe at least three sequences of events which
would get stuck this state diagram after 3 transitions
On state diagrams The diagram represents a) A Document b) A Printer c) A Word-processor d) A User of a word-processor e) A Page being printed f) The diagram is invalid
On state diagrams What is a guard condition in a state diagram? a) An expression comparing the attributes of the modeled
objects against the attributes of the associated object. b) The condition of a person guarding the state diagram from
unwitting destruction by the collaborating designers c) A boolean expression of attribute values which allows state
transition only if condition is true d) A boolean expression that allows the transition from the
state of the current object into a state of another object in the system
e) A state activity that protects object attributes from accidental modification by unconditional actions of state transitions
On state diagrams In a State Diagram, which of the following is true? a) Actions are associated with a transition and are considered to
be processes that occur quickly and are not interruptible b) Actions are associated with transition and are considered to
be processes that occur quickly and are interruptible c) Activities are associated with states and can take longer. An
activity may be interrupted by some event d) Activities are associated with transition that occur quickly and
are not interruptible e) Activities are associated with states and can take longer. An
activity cannot be interrupted by any event
On state diagrams In this diagram a) There are no loops b) There are five states c) Dispatching comes after
Checking d) Waiting is parallel to Delivered e) There are no events f) There are simultaneous events
On state diagrams
• Which condition statement? Wait
Searching
Display results
Display no matches
entry/ Display search page
entry/ Display journal list
entry/ Display NoMatch msg
[empty list]
[else]
User enters search criteria/Query db
Db returns results
On state diagrams Which of the following statements about state
diagrams is correct? a) All actions in a state diagram are attached to
transitions b) An event may cause an object to remain in the
same state it was prior to the event c) Once an object leaves a state, it cannot return to
that state d) Two different transitions out of the same state may
overlap (they can be triggered by the same event)
On state diagrams • What state(s) is the object in after the following
sequence of events? • a b c b g a
On activity diagrams
• Which of the following modeling elements are not found in an Activity Diagram?
a) associations b) swimlanes c) initial node, final node d) fork and join nodes
On activity diagrams • What is the maximum number of
concurrent threads that is possible in this activity diagram?
a) 1 b) 2 c) 3 d) 4 e) 5
On activity diagrams In this diagram: a) Fill Order is executed before Receive Payment b) Overnight Delivery is executed in parallel with
Regular Delivery c) Close Order is executed after Receive
Payment d) Fill Order is executed in parallel with Send
Invoice e) Send Invoice is possibly executed f) Regular Delivery is always executed
On activity and sequence diagrams
• Which sequence diagram is not consistent with the activity diagram?
On sequence diagrams
Which symbol represents a process activation? a) 1 b) 2 c) 3
1
2
3
On sequence diagrams
• Which one of the following fragments of sequence diagram represents the action: "Object A sends to object B several messages named msg”?
a) b) c) d)
On sequence diagrams Which symbol represents a synchronous message? a) 1 b) 2 c) 3
1
2
3
On sequence diagrams What is this in the red oval? a) A message b) A guard c) An event d) An association
On sequence diagrams Given the sequence diagram on right, which class diagram is consistent?
On sequence diagrams
Given the sequence diagram on right, which class diagram is consistent?
On sequence diagrams • What can you say about the control flow of each
of the following systems? – Which is more centralized? – Which is more distributed?
79
On sequence diagrams What is wrong with this sequence diagram?
80
On sequence diagrams What is wrong with this sequence diagram?
81
On sequence diagrams What are the names of missing
classes XXX and YYY in the sequence diagram?
a) XXX = DeliverySchedule,
YYY = Supplier b) XXX = Supplier,
YYY = DeliverySchedule c) XXX = PreferredSupplier,
YYY = DeliverySchedule d) XXX = DeliverySchedule,
YYY = PreferredSupplier
On communication diagrams This diagram contains a) swimlanes and temporal marks b) objects and messages c) classes and associations d) components and events
On communication diagrams These two diagrams are equivalent or not?
On diagrams
Which among these are behavior diagrams? a) Use case diagrams b) Class diagrams c) State diagrams d) Sequence diagrams e) Communication diagrams f) Package diagrams g) Deployment diagrams
On diagrams For understanding event control mechanisms, such as user interfaces and device controllers, which one of the following artifacts is the most useful?
a) Interaction Diagrams b) Activity Diagrams c) Package Diagrams d) State Diagrams e) Class Diagrams f) Communication diagrams g) Deployment diagrams
On diagrams
What is the best diagram type to represent the sentence “all men are mortal”?
a) Use case diagram b) Class diagram c) Object diagram d) Activity diagram e) Communication diagram
Mortal
Man
On diagrams For the business modeling of a human organization or the workflow of a system, which one of the following artifacts is the most useful?
a) Interaction Diagrams b) Activity Diagrams c) Package Diagrams d) State Diagrams e) Class Diagrams f) Collaboration diagrams
On diagrams
What are the nodes in this diagram?
a) Roles b) Actors c) Use cases d) Artifacts e) Events
On diagrams A car has a Starter, some Lights, an AirConditioning System, some Wheels. The driver operates first the Starter, then the Lights, then the AirConditioning System, and finally the Wheels. Which pair of diagrams is most useful to model this situation? a) Use cases and scenarios b) Use cases and class diagrams c) Class and sequence diagrams d) Class and statechart diagrams e) Class and object diagrams
Do-it-yourself exercises Use case diagram describe how to play chess via an interface able to connect
either different engines or a chess server via internet Class diagram describe the pieces, chessboard and the game tree Object diagram describe by object snapshots a chess position during a game Activity diagram describe a game workflow including two players playing via a
(telnet) chess server Statechart describe a game workflow from the viewpoint of the chessboard Sequence diagram describe a multiagent system evaluating a position Communication diagram describe a multiagent system evaluating a position
The UML certification by OMG
References www.pearsonvue.com/omg/!www.objectsbydesign.com/projects/umltest/bparanj-answers-1.html!dn.codegear.com/article/31863!parlezuml.com!www.proprofs.com/quiz-school/story.php?title=quiz-uml-20!
Think about it!