Exercises on 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
Diagrams covered • • • • • • • • • •
Use case Class diagrams Object diagrams State diagrams Activity diagrams Sequence diagrams Communication diagrams Component diagrams Package diagrams Deployment 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 •
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) b) c) d)
A note must be sent to the customer for incomplete mortgage applications, listing the missing items A file must be established for every mortgage application at the time it is submitted, whether the application is complete or not Addresses on mortgage applications must be entered as all capital letters A unique mortgage number must be assigned to each mortgage file. This identifier must follow financial industry standard format
On diagrams Which 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 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 Mortal
b) Class diagram Man
c) Object diagram d) Activity diagram e) Communication diagram
On diagrams For 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 Which sentences are true? a) This is a diagram b) This is a frame c) This is a classifier in UML1 d) This is an artifact e) This is a metamodel element
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 represent 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
On diagrams Which of the following statements is correct? a) Classes in class diagrams may be grouped into packages in order to illustrate the overall organization of a model b) In object diagrams, names of instances are in italics or all-caps c) If package B depends on package A, then any change in A will require a change in B d) Object diagrams and class diagrams are completely interchangeable
On use case 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 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 <> 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 case diagrams a) b) c) d) e) f) g) h)
When you have the final list of use cases, some questions to ask to find out if you have found them all are: Is each functional requirement in at least one use case? Have I considered how each stakeholder will be using the system? Have I missed any technical terms that describes the system? What information will each stakeholder be providing for and receiving from the system? Have I considered the maintenance issues? Have I broken the problem down into pieces that the system will handle? What information will each external system be providing to the system and receiving from the system? Have I identified all of the external systems with which the system will need to interact?
On class diagrams
a) b) c) d) e)
Given that having multiple spouses at the same time is prohibited, but it is allowed to have many spouses over time, which of the following are valid models? The diagram shown represents the concepts to be modeled in the domain and no changes are required. Use the <> stereotype to show the history over time and snapshot in time constraint in the model. Promote the “is married to” association to an association class called Marriage and break up the Many to Many association between Husband and Wife Create a link attribute called “wedding date” and attach it to the association, rather than to either Class in the Association. Create a link attribute called “wedding date” and attach it to either husband or wife class.
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
On objects diagrams Which one is a non valid instance of this model?
a)
b)
c) d)
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 •
a) b) c) d) e) f)
Which of the following are illegal combinations of subtypes in the diagram? Female, Patient, Nurse Male, Physiotherapist Female, Patient Female, Doctor, Surgeon Patient, Doctor 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 class diagrams Which pattern solves the problem shown in the figure? a) Strategy Pattern b) Composite Pattern c) Adapter Pattern d) Bridge Pattern e) Abstract Factory Pattern
On object diagrams
This object diagram a) Includes an anonymous object b) Includes a class c) Includes four instances d) Includes three instances
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 of the following statements about statechart diagrams is correct? a) All actions in a statechart 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 • What is the maximum number of concurrent threads that is possible in the 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 sequence diagrams Which symbol represents a process activation? a) 1 1
b) 2 2
c) 3 3
On sequence diagrams • Which one of the following fragments of sequence diagram represents the action: "Object A sends 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 • What can you say about the control flow of each of the following systems? – Which is more centralized? – Which is more distributed?
39
On sequence diagrams What is wrong with this sequence diagram?
40
On sequence diagrams What is wrong with this sequence diagram?
41
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 a) Contains swimlanes and temporal marks b) Contains objects and messages c) Contains classes and associations d) Contains components and events
On package diagrams Which are true? a) multimediaproject depends on xml b) xml depends on multimediaproject c) xml extends multimedia project d) freighttransportproject depends on xml
On component diagrams These two diagrams a) Are both component diagrams, semantically equivalent b) Are a class and a component diagram, semantically equivalent c) Are different diagrams with different semantics
On class and component diagrams These two diagrams • Are semantically equivalent • The class diagram is semantically richer • The component diagram is semantically richer • Define totally different concepts
On component diagrams How many ports there are in this diagram? a) 1 b) 2 c) 3 d) 4 e) 5
On deployment diagrams Which of the following is true about a deployment diagram? a) Since there is always some kind of response to a message, the dependencies are two-way between deployment components b) Dependencies between deployment components tend to be the same as the package dependencies c) Deployment diagrams cannot be used to show physical modules of code d) Deployment diagrams cannot show the physical distribution of a system across computers
On deployment diagrams What is the symbol for a component inside a deployment diagram? a) Components are not allowed in deployment diagrams b) A rounded rectangle, just like a state in a state diagram c) A 3-dimensional rectangular solid (like a box) d) A rectangle with tabs on its left side
On design patterns Which pair of patterns is correct when designing a software architecture? a) High cohesion and high coupling b) High cohesion and low coupling c) Low cohesion and high coupling d) Low cohesion and low coupling
On design patterns Which GoF pattern is based on a recursive structure? a) Bridge b) Composite c) Abstract factory d) Strategy e) Singleton
On design patterns Which GoF pattern inspires this diagram? a) Bridge b) Composite c) Abstract factory d) Strategy e) Singleton f) Facade
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 Package diagram depict the compile-time structure of a real chess program Component diagram depict the run-time structure of a real chess program interfaced with Winboard and a chess server Deployment diagram Configuration of an ICC telnet server + web site + clients
The UML certification by OMG
References www.pearsonvue.com/omg/ www.objectsbydesign.com/projects/umltest/bparanj-answers-1.html dn.codegear.com/article/31863
Think about it!