SDM Lab 1: Relating UML and Java, using Umple

This page gives brief notes and instructions on the guided lab session. It will have omissions and bugs - you need to listen 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, rather than going straight to the industrial strength (but more complex) software we'll use for most labs. We will use the online service Umple Online (open that link in a new tab now). A known problem is that it may struggle with the number of simultaneous users we have. Therefore you'll work in pairs for this lab. Let me know if it becomes too unresponsive even so!

Hello World

Get into pairs, each pair at one machine... agree whose account you're going to work under... swap email addresses or other means of contact, so that you can exchange any useful files afterwards...

Look at Umple... listen to the explanation of what it is...

Follow the page Hello World Examples of the Umple user manual. Have a play. 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!)

Going the other way

A fairly common usecase in software maintenance is that you start from a body of code and you need to build a model from it: that is, you form the abstraction. Sometimes you will then use the model to generate code in another language, or sometimes it's documentation. Here you'll do a very simple version of this task.

Here you will find a collection of Java code. Download and unzip it. Your task is to try to build a UML model which generates exactly this Java code.

You may find a shell for-loop useful for checking, e.g. if the given code is in directory Java and the code generated from your current model is in Java1, you could look at the remaining differences using this shell command:

for file in `ls Java`; do diff Java/$file Java1/$file; done

(Note that if there are no differences, as you wish, then the slightly disconcerting result of this command is that it will print nothing at all. If you want to verify that that's what's happening, put a dummy change in one of the files, creating a difference, and verify that if you rerun the command that one does get reported!)

As you go, look carefully at the generated code. Look particularly at what it does with attributes and associations. How are the choices you make for multiplicities connected with the code that gets generated? Do you see any oddities in the generated code, and can you explain why the developers of the code generator have made the choices they have? Are there any places where, to do this artificial exercise, you have to make choices in your model that actually don't matter? Are there any differences you can't eliminate?

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.

(If time, else afterwards.)

  1. 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.
  2. 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.

  3. 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...)
  4. 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?
  5. 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?

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?

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.)


This page is maintained by Perdita Stevens (perdita@inf.ed.ac.uk)


Home : Teaching : Courses : Sdm 

Informatics Forum, 10 Crichton Street, Edinburgh, EH8 9AB, Scotland, UK
Tel: +44 131 651 5661, Fax: +44 131 651 1426, E-mail: school-office@inf.ed.ac.uk
Please contact our webadmin with any comments or corrections. Logging and Cookies
Unless explicitly stated otherwise, all material is copyright © The University of Edinburgh