exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing...
Transcript of exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing...
![Page 1: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/1.jpg)
Exercises on basic UML: structures
Paolo Ciancarini
![Page 2: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/2.jpg)
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
![Page 3: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/3.jpg)
Diagrams covered • Class diagrams • Object diagrams • Domain diagrams • Context diagrams • Feature diagrams
![Page 4: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/4.jpg)
Think about it!
![Page 5: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/5.jpg)
Reading exercises • Read the UML class diagram • Pay attention to the multiplicity • Try to understand the relationship and
describe it in natural language
![Page 6: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/6.jpg)
Veterinary System • Try to read & understand this UML diagram
![Page 7: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/7.jpg)
Veterinary System • Read and understand this UML diagram
• 1 or more Pets associated with 1 PetOwner • Each pet has exactly one PetOwner
![Page 8: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/8.jpg)
Computer System
![Page 9: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/9.jpg)
Computer System
• 1 CPU associated with 0 or more Controllers • 1-4 DiskDrives associated with 1 SCSIController
• SCSIController is a (specialized) Controller
![Page 10: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/10.jpg)
Library System
![Page 11: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/11.jpg)
Library System
• 1 or more Book associated with 1 or more Pages • Patron & Shelf use (depend on) Books
![Page 12: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/12.jpg)
Banking System
![Page 13: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/13.jpg)
Banking System
• 1 Bank associated with 0 or more Accounts • Each Account is associated with exactly one bank
• Checking, Savings, and MoneyMarket are Accounts
![Page 14: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/14.jpg)
Home Heating System
![Page 15: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/15.jpg)
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
![Page 16: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/16.jpg)
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)
![Page 17: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/17.jpg)
Printing System
![Page 18: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/18.jpg)
Family
A woman can have as sons two twins?
![Page 19: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/19.jpg)
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
![Page 20: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/20.jpg)
![Page 21: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/21.jpg)
Solution
![Page 22: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/22.jpg)
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
![Page 23: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/23.jpg)
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
![Page 24: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/24.jpg)
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
![Page 25: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/25.jpg)
On class diagrams
This diagram describes a) a sequence b) a domain c) a system d) a use case e) a temporal behavior
![Page 26: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/26.jpg)
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
![Page 27: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/27.jpg)
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
![Page 28: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/28.jpg)
On class diagrams The arrow between the two classes indicates: a) Inheritance b) Association c) Dependency d) Sending a message
![Page 29: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/29.jpg)
On class diagrams
![Page 30: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/30.jpg)
On class diagrams
![Page 31: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/31.jpg)
On class diagrams
A visitor register is made of visitor entries
![Page 32: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/32.jpg)
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
![Page 33: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/33.jpg)
On class diagrams:
• Right or wrong? Student
- passedModules: list of Strings
Module - name:String - code:int
![Page 34: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/34.jpg)
Module
- name: String
- code: int
prerequisites + equivalents
On class diagrams
• Right or wrong?
*
![Page 35: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/35.jpg)
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
![Page 36: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/36.jpg)
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); !!
![Page 37: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/37.jpg)
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
![Page 38: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/38.jpg)
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
![Page 39: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/39.jpg)
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
![Page 40: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/40.jpg)
On object diagrams
• This object diagram is instance of which class diagram(s)?
Car
Wheel
Engine Car
Wheel
Engine Car
Engine Wheel
![Page 41: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/41.jpg)
On object diagrams
This object diagram a) Includes an anonymous object b) Includes a class c) Includes four instances d) Includes three instances
![Page 42: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/42.jpg)
On object diagrams
Which diagrams are correct?
Person
:John
Person
Man
Person
:John
Person
Man
a) b) c) d)
![Page 43: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/43.jpg)
On objects diagrams
Which one is a non valid instance of this model?
a) b)
d)
c)
![Page 44: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/44.jpg)
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)
![Page 45: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/45.jpg)
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
![Page 46: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/46.jpg)
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!
![Page 47: exercises on UML basic structures - unibo.itcianca/ · • This is a set of exercises on writing and ... Do-it-yourself exercises Use case diagram describe how to play chess via an](https://reader031.fdocuments.in/reader031/viewer/2022022018/5b860c317f8b9a162d8c14a5/html5/thumbnails/47.jpg)
Think about it!