Introduction to Software Engineering/UML/Examples
Labs[edit | edit source]
Lab 1a: StarUML (30 min)[edit | edit source]
We need to learn about a UML modelling tool. StarUML is a free UML modelling tool that is quite powerful, it allows for forward and reverse engineering. It supports Java, C++ and C#. A small disadvantage is that it is no longer supported, hence it is limited to Java 1.4 and C# 2.0, which is very unfortunate.
Start StarUML, and select ’Empty Project’ at the startup. Then in the Model Explorer add a new model by right-clicking on the ’untitled’ thing. After that you can create all kinds of UML diagrams by right-clicking on the model.
More details can be found at the following StarUML Tutorial. 
Lab 1b: objectiF (30 min)[edit | edit source]
Lab 2: Restaurant Example (30 min)[edit | edit source]
Take the restaurant example from class and create all the different UML diagrams we created in class using StarUML or your favorite UML modelling tool.
Once you are done with the class diagram, try out the 'Generate Code' feature. In StarUML you right-click with your mouse in the class diagram, and select 'Generate Code'. Look at the classes generated and compare them with your model.
Important Note: the restaurant example actually is not a very good example, because it may give you the impression that actors become objects. They don't. Actors never turn into objects, actors are always outside the system, hence the Tetris example below is much better.
Lab 3: Tetris (60 min)[edit | edit source]
Most of us know the game of Tetris.  (However, I had students who did not know it, so in case you don't please learn about it and play it for a little before continuing with this lab). If you recall from class, when inventing UML, the Three Amigos started with something that was called Object Oriented Analysis and Object Oriented Design. So let's do it.
Object Oriented Analysis and Design[edit | edit source]
We want to program the game Tetris. But before we can start we need to analyze the game. We first need to identify 'objects' and second we must find out how they relate and talk to each other. So for this lab do the following:
- build teams of 5 to 6 students per team
- looking at the game, try to identify objects, for instance the bricks that are dropping are objects
- have each student represent an object, e.g., a brick
- what properties does that student/brick have? (color,shape,...)
- how many bricks can there be, how do they interact?
- is the player who plays the game also an object or is she an actor?
- how does the player interact with the bricks?
- what restrictions exist on the movement of the bricks, how would you implement them?
- how would you calculate a score for the game?
Game Time[edit | edit source]
Once you have identified all the objects, start playing the real game. For this one student is the 'actor', one student will write the minutes (protocol), and the other students will be objects (such as bricks). Now start the game: the actor and the different objects interact by talking to each other. The student who writes the minutes, will write down who said what to whom, i.e., everything that was said between the objects and the actor and the objects amongst themselves.
Play the game for at least one or two turns. Does your simulation work, did you forget something? Maybe you need to add another object, like a timer.
UML[edit | edit source]
We now need to make the connection between the play and UML.
- Use Case diagram: this is pretty straightforward, you identify the actor as the player, and write down all the use cases that the player can do. One question you should check, if the timer is an actor. The Use Case diagram tells you how your system interacts with its environment. Draw the Use Case diagram for Tetris.
- Activity diagram: from your game you find that there is some repetition, and some decisions have to be made at different stages in the game. This can be nicely represented with an Activity diagram. Draw a high level Activity diagram for the game.
Next we come to our minutes (protocol): this contains all the information we need to draw a Sequence diagram and finally arrive at the Collaboration diagram.
- Sequence diagram: take a look at your minutes (protocol). First, identify the objects and put them horizontally. Then go through your minutes line for line. For every line in your minutes, draw the corresponding line in your Sequence diagram. As you can see the Sequence diagram is in one-to-one correspondence with the minutes.
- Collaboration diagram: from the Sequence diagram it is easy to create the Collaboration diagram. Just do it.
- Class diagram (Association): from the Collaboration diagram, you can infer the classes and the methods the classes need. As for the attributes, some you have already identified (like the color and shape of the bricks), others you may have to think about for a little. Draw the class diagram, and for every class try to guess what attributes are needed for the class to work properly.
- Class diagram (Inheritance): if you have some more experience with object-oriented languages, you may try to identify super classes, i.e., try to use inheritance to take into account common features of objects.
If you performed this lab properly, you will have learned a lot. First, you have seen that through a simulation it is possible to identify objects, connections between the objects, hidden requirements and defects in your assumptions. Second, using a carefully written protocol of your simulation is enough to create Sequence, Collaboration and Class diagrams. So there is no magic in creating these diagrams, it is just playing a game. Although you may think this is just a funny or silly game, my advice to you: play this game for every new project you start.
References[edit | edit source]
- http://staruml.sourceforge.net/en/ StarUML - The Open Source UML/MDA Platform
- http://cnx.org/content/m15092/latest/ StarUML Tutorial
- http://www.microtool.de/objectif/en/index.asp objectiF - Tool for Model-Driven Software Development with UML
- http://www.microtool.de/mT/pdf/objectiF/01/Tutorials/JavaTutorial.pdf Developing Java Applications with UML
- http://en.wikipedia.org/wiki/Tetris Tetris
- http://www.percederberg.net/games/tetris/index.html Java Tetris
Questions[edit | edit source]
- Give the names of two of the inventors of UML?
- Who mananges the UML standard these days?
- Draw a UseCase diagram for the game of Breakout.
- Take a look at the following Activity diagram. Describe the flow of information in your own words.
- In class we introduced the example of a restaurant, where Ralph was the customer who wanted to eat dinner. His waiter was Linus, the cook was Larry and Steve was the cashier. Ralph was ordering a hamburger and beer. Please draw an Sequence diagram, that displays the step from the ordering of the food until Ralph gets his beer and burger.
- Consider the following class diagram. Please write Java classes that would implement this class diagram.
- You are supposed to write code for a money machine. Draw a UseCase diagram.
- Turn the following Sequence diagram into a class diagram.
- What is the difference between Structure diagrams and Behavior diagrams?