Introduction to Software Engineering/UML/Examples

< Introduction to Software Engineering < UML

Labs

Lab 1a: StarUML (30 min)

We need to learn about a UML modelling tool. StarUML[1] 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. [2]


Lab 1b: objectiF (30 min)

Another UML modelling tool, which is free for personal use is objectiF.[3] To learn how to use objectiF, take a look at their tutorial.[4]

Lab 2: Restaurant Example (30 min)

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)

Most of us know the game of Tetris.[5] [6] (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

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:

Game Time

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

We now need to make the connection between the play and UML.

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.

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 you 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


Questions

  1. Give the names of two of the inventors of UML?
  2. Who mananges the UML standard these days?
  3. Draw a UseCase diagram for the game of Breakout.
  4. Take a look at the following Activity diagram. Describe the flow of information in your own words.
  5. 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.
  6. Consider the following class diagram. Please write Java classes that would implement this class diagram.
  7. You are supposed to write code for a money machine. Draw a UseCase diagram.
  8. Turn the following Sequence diagram into a class diagram.
  9. What is the difference between Structure diagrams and Behavior diagrams?
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.