Pimp My Diagram
The Pimp My Diagram series discusses some issues in UML sequence diagrams and shows you how to improve your own diagrams.
Each episode features the makeover of a single sequence diagram, either picked from the web or submitted by a reader.
Episode 2 - Three little pigs (s01e02)
This short episode of Pimp My Diagram features a sequence diagram from a blog post made by Ken Howard, called 'The three little pigs in UML'. For prosperity's sake, here's a copy of the .pdf file he posted.
(If you need a refresher on UML sequence diagrams, check out this quick introduction to UML sequence diagrams)
The original UML sequence diagram
I've extracted the sequence diagram from the pdf file, to make it a bit easier to compare the original and the improved versions.
Have a look at the original sequence diagram (click to enlarge) :
Some of the questions that came to mind when viewing the above diagram were
- Why are all the messages asynchronous?
- Why do only the wolf and pigs objects have activation bars on their lifelines?
- How can Wolf and Pig objects start sending messages spontaneously if they're not active objects?
- Why use so many messages to self on a diagram that is meant to show interaction?
- Why are the Pig objects named?
- Why not use a constructor to indicate the creation of the houses?
- Why not use a destruction cross to end the lifeline of the destroyed houses?
- Why number the messages if they're never referred to?
There's a lot of room for improvement -and not just in the sequence diagram. But keep in mind that Ken's post was meant to be entertaining, it is not a model of anything.
How it was done
The original diagram was recreated and improved using Trace Modeler, the easy-to-use and smart UML sequence diagram editor.
If you are still looking for a better way to create your UML sequence diagrams, check out the 30 sec demo to see how easy it really is..
Here are some exported versions of the improved diagram :
- Portable Network Graphics (.png)
- Scalable Vector Graphics (.svg)
- Portable Document Format (.pdf)
- Encapsulated Postscript (.eps)
Ok, that concludes the commercial break, on with the show!
The improved UML sequence diagram
Since the purpose of Ken's post was to tell the story of the three little pigs using UML, I've taken the liberty to change the model a bit as well. Specifically, I didn't like the messages eat, climbDown and fallInto because they are either badly named or on the wrong object (depending on your viewpoint).
Here is the pimped version of the diagram (click to enlarge)
You'll notice that I've put the construction of the houses at the beginning of the story. That gave me the opportunity to use a 'par' combined fragment to indicate that the construction happens concurrently. I don't get to use those very often, so I just couldn't resist. Incidentally, it is also how I remember the story
The Wolf and Pig objects were made into active objects. This means they can start sending messages without prior stimulus. I thought it would be a nice touch to apply the actor stereotype to them -this is a story after all- hence the stick men.
I've also removed all messages to self, as they are not needed for communication. This is actually something I see very often : people resort to self-messages to explain what an object is doing at some point in the interaction. The problem with such an approach is that it implies that the object actually supports messages to that extent, which is usually not the case. There are two better ways to explain what an object does 'internally' : either use a comment or an action. I prefer comments in this matter.
Pigs, wolves and houses that were unfortunate enough to either get eaten, boiled or destroyed now have a destruction cross on their lifeline to indicate that they're no longer needed.
Another area where many diagrams can be improved, is in the naming of their objects. Not so much in the actual names being used, but rather in the choice of whether an object should be named at all. In this diagram, the Wolf and Chimney objects were named because they are used as message parameters during the interaction. All other objects remain anonymous. Also notice the use of 'this' as a parameter when sending an accept message to the Chimney.
Luckily, this is just an attempt to tell the story of the three little pigs using a UML sequence diagram. If it were part of (the documentation of) a real model, I'd wonder how the wolf obtains a handle to the pigs, their houses, how the PotOfWater gets connected to the Chimney, etc.
Improving the class diagram
I don't discuss class diagrams in this series, but some thoughts about Ken's class diagram :
- Why do pigs need a name property?
- Why are there no messages on this overview diagram?
- Why use a composition to model the relation between the story and its actors, when they're not clearly defined anyway?
- Why use a lower bound of 1 for the multiplicities in the association between Chimney and PotOfWater? It implies that the Chimney needs to construct the PotOfWater, or vice-versa.
I found Ken's post to be entertaining, it was fun to figure out the best way tell his version of the story using a sequence diagram. So thank you Ken for posting!
If you want me to pimp your diagram or have seen an interesting one somewhere, send it to me and I'll try to feature it in an upcoming article!
If you have any questions, want to give feedback about this article or have suggestions on how to improve Trace Modeler, send them in and I'll add them below.
None so far
Article copyright © Yanic Inghelbrecht 2008, www.tracemodeler.com | last updated on 06/07/2008