Welcome!

Java Authors: Maureen O'Gara, Liz McMillan, Walter H. Pinson, III, Yakov Werde, Tony Bishop

Related Topics: Java

Java: Article

Observed Benefits of the Unified Modeling Language

The UML is designed to serve you

Activity Diagram
Once the requirements of a system from the users' perspective have been defined, activity diagrams help to define how this user experience will be achieved.

Activity diagrams are also extremely powerful. They are well suited to fleshing out the details of a use case by modeling the detailed interaction between a user and a system or screen. Activity diagrams are used to model:

  • Business processes.
  • Flow of control in an executing program.
  • Details of a method.
They are a close relative of the traditional flowchart (see Figure 2). As you identify and diagram the different activities, you'll naturally see a pattern of objects emerge to which the different activities can be assigned. You can use the swim lanes to assign responsibilities to different objects - whether those objects are people or software.

Class Diagram
Class diagrams are used to model the classes of objects in a system (people and software). In the context of this article, the software building blocks are likely to be Java classes.

Think of a class - it has properties (attributes and associations) and methods and can be represented as shown in Figure 3.

The Order class has an orders property, which is an array of order items, each one represented by an OrderItem object. Although this could simply have been shown as an attribute inside the class, it's often more meaningful to represent such a property using an association as above.

On this point, I found Martin Fowler's excellent book, UML Distilled, particularly helpful. I highly recommend it. He goes into class diagrams in some detail and wisely splits his coverage into two chapters, focusing the first chapter on the essentials.

Class diagrams seem to follow so naturally from activity diagrams; the activities identified often may neatly correspond to methods in a class diagram, which helps save time and increase productivity.

There is, of course, no requirement to identify every property or method on a class in a class diagram. You may choose to show only public methods for example. Equally, you don't have to show all classes and relationships between them. Again, use what works for you.

Class diagrams really help when architecting the system and seem to give the design "room to breathe." It seems that if the design is elegant, the implementation is elegant too. If the implementation is elegant, it can be more pleasurable and cost-effective to evolve and maintain on an ongoing basis once the system has been put into production.

In Ian Sommerville's definitive work, Software Engineering, he cites (and qualifies) research that suggests up to 90% of software costs are evolution costs. Looking at this another way, if all you build for a client is the initial implementation of a system, you may only be getting as little as 10% of the revenue stream that you would otherwise get from that client over the lifetime of the system. Of course, these figures will vary significantly, but it's an interesting thought.

If you build a system that can be evolved elegantly and cost effectively, you're more likely to keep the relationship with the client, give them a better service, and make more money. Class diagrams are great for organizing where functionality will go, and for helping to select consistent and meaningful property and method names.

Sequence Diagram
Have you ever developed an application and then had to come back and modify it six months later and tried to work out how on earth you did it? Well, the UML sequence diagram may be able to help you.

A sequence diagram models the sequence of interactions between objects. In some ways, it a close cousin of an activity diagram, yet focused more on the behavior of software objects on a timeline (see Figure 4).

Sequence diagrams are great for thinking through a design, illustrating an idea, and also getting back up to speed when changes need to be made six months or so after the system has gone into production. The design stands out so clearly.

Prior to finding out about the UML, I used my own non-standard diagrams. For me, the biggest single benefit of the UML has been the sequence diagram.

In the UML modeling tool I use, MagicDraw UML, I typically have a class diagram open at the same time as a sequence diagram. As I work on the design and identify additional methods, I add these to the appropriate class. These methods are then immediately available for me in the sequence diagram. As a result, it's much easier to create an elegant design and enhance productivity. Another powerful feature of MagicDraw UML is that it enables me to generate all the framework code in Java from the UML model at the click of a button (equally, I can reverse engineer a sequence diagram from Java code).

It also ensures that the design is the documentation, which ensures that the documentation is done as the design evolves, changing with it. The appropriate use of annotated UML diagrams can save time, which is a significant business benefit.

In addition, it becomes a pleasure to come back and add additional functionality at a later date.

Getting Started with the UML
Here's what worked for me and what I generally suggest to anyone interested in getting started:

  • Get a tool such as MagicDraw UML (free community edition and trial available). Tools have a lot of intelligence built in, which helps you get up to speed quickly on a couple of diagram types. The tool knows the specification. Have a look at the various symbols available in one or two of the main diagram types described above. Start using some of the symbols; you don't have to use them all. Grow into the tool over time. Learn the structure of the documentation and start reading it.
  • Get Martin Fowler's book, UML Distilled. Read it a couple of times. It's a great book, aptly titled. I found Martin's real-world experience and balanced view of using the UML very helpful.
Remember that the UML is a language, not a methodology, so don't think you have to change everything you already do successfully in order to get started with the UML. Take it one diagram at a time. Used effectively, the UML offers significant benefits.

Resources

More Stories By Duncan Jack

Duncan Jack started the Scottish CFUG (www.scottishcfug.com), which is now ably run by Andy Allan. Duncan recently founded Scottish Java (www.scottishjava.com), a brand new Java community. A Macromedia Certified Flash MX 2004 Developer, his main interests are in building innovative Rich Internet Applications using Flash, Flex, ColdFusion and JRun. An accomplished mountaineer, he holds a first-class honours degree in Civil Engineering and is currently studying for an M.Sc. in Advanced Computer Science.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.