Learning UML

A few years ago I decided to familiarise myself with UML. My first step was to seek some advice from colleagues on what might be a good book about the subject. The book that came highly recommended to me was Martin Fowler’s UML Distilled.

Having used his book to learn UML I cannot recommend it strongly enough. He has done a brilliant job of taking a large subject and condensing it so that you can get up to speed with it quickly and enjoyably.

Whilst I read his book I applied the various UML diagramming techniques to code that I had already written so that I could get a feel for how they worked. Whilst learning I drew all my diagrams by hand. I found that this not only aided my learning but also developed my ability to draw diagrams on a white-board or flip chart during design discussions rather than having to rely on using a software tool.

The techniques from UML Distilled that I have personally found the most useful are as follows:

Class Diagrams

Class diagrams are probably the most popular UML diagram type. They allow you to design software classes in a way that is language independent (to some extent). They are the most common use of UML that I have seen but I am not convinced about how much benefit they provide. I think that with modern development environments you might as well create skeleton classes in the language you intend to use (That is probably a subject for another blog!).

Where I have found class diagrams useful is for business analysis. In this context they allow you to communicate entity relationships to non-technical people. You know the sort of thing: employees have managers, managers are employees, employees can have more than one manager but only one line manager, and so on.

Another area where I feel they add benefit is when you are designing changes to existing code. Used like this I recommend producing diagrams that don’t show all the properties and methods of existing classes but only those that are relevant to the change being carried out. In this way the diagram helps by showing clearly what is to be changed without the “noise” of other, unrelated, areas of the existing system.

State Machine Diagrams

State machine diagrams are, apparently, an unglamorous side of UML that few people are interested in. Nonetheless I have found them brilliant for mapping out the flow of a user interface. In this context every screen in the application becomes a state and every transition shows how a user can move from one screen to another. This quickly shows if you have any glaring omissions (i.e. no way to cancel a transaction). Also, as your development project moves from design to coding, a state diagram helps developers understand how their part of the application’s user interface relates to others.

I should add that, more generally, state diagrams are very good for designing any software that has to react to external events. When designing communications protocols I have often used state diagrams. The states typically become things like waiting for a message, message received, response sent, and so on. A state diagram quickly flushes out all the “what ifs” like what happens if the received message is corrupt?

Use Cases

Use cases are not, strictly speaking, part of UML but Martin Fowler includes information about them in his book because they are related to use case diagrams. Use cases provide an excellent and structured approach for gathering functional requirements. Documented use cases are very useful not just for documenting the requirements but also for allowing developers to understand how the software they are writing will be used. On one project I worked on I instituted a practice of including relevant use cases in the technical specifications given to developers so that they could properly appreciate what the software they were writing was aiming to achieve.

If you liked this you might also like some of my other posts about software design and requirements:


No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: