SDM: Lab 1: Relating UML and Java, using Umple

This page gives brief notes and instructions on the lab session. It will have omissions and bugs - you need to think as well as read!

Introduction

The main aim of this lab is to explore the ideas of consistency between a model - a graphical, abstract model of some software - and the code itself, e.g. in Java.

To make this easier we will use a piece of software designed for teaching, Umple. We will use the online service Umple Online (open that link in a new tab now).

If you like to work in pairs, feel free - provided that everyone ends up understanding that is fine.

1. Class diagrams

Hello World

Follow the page Hello World Examples of the Umple user manual. Have a play with Umple Online. Notice that the textual representation on the left looks a lot like Java but is not Java: you can generate Java using the button in the middle. Look carefully at the Java that is generated, and compare the Umple code (on the left) with the UML diagram (on the right). Try generating code in other languages. Tweak things and regenerate, understand what changes...

More complex example

Consider the following text, taken from Lethbridge and Langaniere Appendix C.

Ootumlia Airlines runs sightseeing flights from Java Valley, the capital of Ootumlia. The reservation system keeps track of passengers who will be flying in specific seats on various flights, as well as people who will form the crew. For the crew, the system needs to track what everyone does, and who supervises whom. Ootumlia Airlines runs several daily numbered flights on a regular schedule. Ootumlia Airlines expects to expand in the future so the system needs to be flexible: in particular, it will be adding a frequent-flyer plan.

Develop a conceptual class model for the reservation system. Start by identifying key classes, and add associations and attributes. Are there any generalizations? Finally, look at the version under the Airline entry in the Examples menu. Are there differences from what you developed? Discuss why that might be. (It does not necessarily mean your version is wrong!)

2. State diagrams

Load the Booking (airline) example and examine the text and diagrammatic representation. (By the way, the UML side uses the wrong type of arrow head: in a state diagram the arrows should be ordinary line arrows, ->, not filled in triangles.)

Add a new transition to represent that if a Booking receives a message unchecking while it is in state checkedIn, it goes back to state seatAssigned.

Generate Java code and examine it. What happens if a Booking object receives a cancel message while in state Completed? Is this a problem? What else might you have expected? Later, look into the official UML specification to see whether the code generator's behaviour is correct according to the spec.

Look at Digital Watch (nested) and at Tic Tac Toe. Check you understand the action and condition notations that they use.

 

Read the Basic State Machines Umple tutorial page. Look carefully at the Garage example diagram. Check that you understand the entry, exit and do actions.

Load the Umple code for Garage (not Garage Door: you want the second block of Umple code, under heading Garage Door Example with Actions) into UmpleOnline using the link provided on the tutorial page. You may also find it helpful to watch the video near the bottom of the page.

UmpleOnline will show a diagram, but it doesn't look exactly like the one in the tutorial page: it doesn't show the entry, exit and do actions. The Umple code does include those, though: check you understand.

What this means is that the Umple code now has some information that's not in the Umple diagram. The diagram and the code are consistent, but not isomorphic. Does the diagram contain any information not in the Umple code? (If so, is any of that information important? Discuss...)

Noticing that the diagram generator can apparently cope with actions that occur on transitions, but not with entry/exit/do actions, can you change the Umple code without changing its semantics so that a UML diagram will be produced that does contain all the necessary actions?

If you succeeded, you've demonstrated that UML contains redundancies: you have now seen two UML state diagrams that mean the same. Is that a deficiency in UML? Are there circumstances where one diagram would be more useful than the other?

3. To discuss

What can you learn from the experience of using Umple? Can you envisage it or something like it being useful in real software development? What flaws does it have, and do you think these arise from it being academic rather than commercial software, or are they unavoidable? Did you find yourself making certain changes in the textual representation and others in the diagrammatic representation?

4. After the lab

Take some time to go through the lab sheet again, and check that you now understand all the points of Java and UML that arose, and have thought about all the discussion points. (If not, or if you need to discuss further, Piazza is the right place.) There's a lot more material on the Umple page that you may find helpful and/or interesting: have a browse. (Tip: UmpleOnline seems to work better in the morning than the evening: most of its users are in North America.) 

License
All rights reserved The University of Edinburgh