Having looked at why UML is useful, and where it came from, we'll now look at the notation itself. To cover the complete notation in a single chapter would be impossible, so for a deeper coverage I'll refer you to some other works.
What we'll do here is cover the essential notation and core concepts that will allow us to progress through the rest of the book with a common understanding. We'll also aim to address one of the problems of many UML courses and books. The problem being, that all too often the various diagrams are presented in isolation without a clear indication of how they relate to one another. To make matters worse, different examples are often used to demonstrate the different diagrams, not one of those examples being for a system that you might actually want to build. Think here of a statechart diagram that describes a motor car gearbox, or a sequence diagram that describes the operation of a hotel elevator. So in the following section we'll have a single example, an Order Processing system, which you should be able to relate to even if you don't intend to build such a thing, and at the end, we'll pull it all together.
UML Essential Notation and Core ConceptsNow we'll step through the UML diagrams in turn, all the way from an activity diagram through to a deployment diagram in this order:
Each diagram is labeled in light gray with some of the names given to the UML elements that are shown, which - for the record - reflects the UML metamodel.
On the whole, the model elements have been labeled using Visio EA terminology so as to reduce the potential for confusion when you come to use the tool. Historically - and in other modeling tools - you may have encountered alternative UML terminology. The alternative terms have been tabulated towards the end of this chapter. As you'll see later in this chapter, the software development process that you follow might well be described as use-case driven, which implies the use case diagram as an obvious starting point. But those use cases will doubtless fit into some kind of overall business process, perhaps modeled up-front by a business analyst. So we'll take a business process as our starting point and use this as a vehicle for demonstrating the most suitable diagram for that purpose; the activity diagram.
Activity DiagramThe activity diagram is the closest you'll get in UML to a flow chart, and the closest you'll get to a business process diagram. Here is a sample activity diagram with the important UML elements labeled, followed by a description of those elements.
What the diagram showsThe Order Processing business process begins when an Order Clerk performs the Take Order activity. This activity results in an Order object being created in unpicked state. Next, the Pick Stock activity is performed (for the Order) by the Logistics team. At this point some parallel behavior occurs - the Logistics team Deliver Item(s) around the same time that the Accounts department Prepare Invoice. Only when the items have been delivered and the invoice has been prepared can the Accounts department then Send Invoice. Immediately prior to sending the invoice they must Print Invoice. Those are the essential points of an activity diagram, but not a complete coverage. In particular you will see some additional syntax in the description of a Statechart diagram.
Use Case DiagramHere is a sample use case diagram with the important UML elements labeled, followed by a description of those elements.
A Note about StereotypesYou might wonder why the words <<uses>> and <<extends>> are enclosed within angled brackets << like this >>. It's because they are stereotypes; these allow a single UML element (in this case a generalization line with a triangular head) to represent slightly different concepts.
What the Diagram ShowsTaking the original activity diagram as a starting point, each of the activities - Take Order, Pick Stock, Deliver Items, Prepare Invoice, and Send Invoice - has been represented as a use case. A one-to-one correspondence between activities and use cases is not mandatory, but here it shows the potential for traceability between the diagrams. You will also see a correspondence between the actors in this diagram and the swim lanes from the original activity diagram. The Order Clerk swim lane is represented as an Order Clerk actor, the Logistics swim lane is represented by DeliveryMan and StockPicker actors, and the Accounts swim lane is represented as an Accountant actor. Choose Order represents functionality that is common to (used by) the Deliver Items, Prepare Invoice, and Pick Stock use cases. To deliver items, prepare an invoice, or pick stock the actor must first choose an order, but to take a new order the actor does not need to first choose an order (obviously) and to send an invoice the actor need not chose an order (because they will choose an invoice). In the course of taking an order, the Take Order use case may be extended by functionality to Mark for Special Delivery. This has been modeled separately as an extension so that the extended behavior may be changed with no impact on the main use case; for example, this extension may bypass the standard procedure and instead send an instant message to the Stock Picker and Delivery Man.
Sequence and Collaboration DiagramUse cases are realized (that is, described in terms of interactions between collaborating objects) using interaction diagrams, of which there are two types:
Here is a sample sequence diagram with the important UML elements labeled, followed by a description of those elements.
Here is an equivalent collaboration diagram showing the same set of interactions. Whereas a sequence diagram has a top-to-bottom time line to show the order of events, a collaboration diagram uses a numbering scheme. Apart from the visualization style, sequence diagrams and collaboration diagrams may be thought of as equivalent to the extent that some modeling tools, such as Rational Rose, allow automatic switching between the visualization styles.
What these Diagrams ShowBoth diagrams show the sequence of object interactions that support the PickStock use case. The sequence is:
Statechart DiagramThe inclusion of Order as an object in state in the original activity diagram hints at the fact that this will be a state-full class. We could have included the object multiple times on that diagram to show the state changes of an Order that result from the various activities, but for clarity we didn't. To show the complete set of states for an Order, and - most importantly - to show the circumstances in which an Order will transition from one state to another, we draw a Statechart diagram. Here is a sample Statechart diagram with the important UML elements labeled, followed by a description of those elements.
What the Diagram ShowsUpon receiving the create event, the Order transitions from the initial state into state Unpicked. When an allocateStock event occurs the Order will return to the Unpicked state if the [stock not available] condition is true, otherwise - if the [stock available] condition is true and the removeltem action completes - then it will transition to state Picked. Alternatively the transition from state Unpicked may be to state Canceled if a cancel event is received. The order may transition to state Delivered, from state Picked, upon receiving a deliver event. It may transition to state Invoiced, from state Delivered, upon receiving an invoice event. When Canceled or Invoiced, that's the end of the line for this Order, so there is a notional transition to the end state.
Static Structure DiagramThe sequence diagrams, collaboration diagrams, and statechart diagrams that we've encountered in the previous two sections are termed dynamic diagrams. They represent the dynamic model, which is the model showing how our system will behave over time. We also need a static model, showing the persistent relationships and dependencies between classes and components. Out first static model will be the Static Structure diagram (Visio terminology), which is otherwise more commonly known as the class diagram. Here is a sample class diagram with the important UML elements labeled, followed by a description of those elements.
What the Diagram ShowsPickStockController and ChooseOrderController are specializations of a generalized class called Controller. In our design, all controller classes will be subclasses of the Controller super-class. The PickStockController class depends on the ChooseOrderClass class, the StockltemsForm class, and the Warehouse class. Look back at the sample sequence diagram to see how the PickStockController calls operations of those other classes. The ChooseOrderController depends on the Order class by virtue of the fact that it displays orders. A Warehouse instance owns aggregate StockItem instances according to the following aggregation: 1 (multiplicity) Warehouse (class) location (role) holds stock (association name) of * (many multiplicity) stockedItem (role) StockItems (class). Each Order instance is associated with one or more (1..*) StockItems, with linked stock items taking the role of orderedItem. For each such link there arises a StockAllocation instance that holds the date that the stock was picked and allocated. The static structure diagram (class diagram) shown here as an example does not contain the complete set of classes for the entire application, but rather those classes that are relevant to the Pick Stock use case. As such, it represents View of Participating Classes (VOPC) for that use case.
Component DiagramAn application will be delivered or deployed typically not as individual classes or even a package of classes, but rather as one or more deployable components - executables or libraries - into which the classes or packages have been collected.
Here is a sample component diagram with the two component types described overleaf:
The component diagram is a static diagram, just like the class diagram, because it shows how the application is organized rather than how it will behave over time.
What the Diagram ShowsOur application will comprise a main executable program, the OrderProcessingApp deployed as file OrderProcessingApp.exe. This program will depend on a library of control classes deployed as file Controllers.dll, which in turn will depend on two more component libraries: Forms.dll and Entities.dll. We've hinted at the fact that components represent deployable collections of classes. For this example, the mapping of classes onto the <<library>> components will be:
Note that this is just one way in which classes may be mapped on to components, in this case according to the types of each class: form, control, or entity. You might instead decide to package classes onto components according to application subsystems, for example StockControl.dll (containing forms, controls, and entities relating to stock control functionality) and OrderHandling.dll (containing forms, controls, and entities relating to order handling functionality).
Deployment DiagramThe final UML diagram we'll look at is the deployment diagram, the purpose of which is to show the physical nodes on which the software components will actually be installed. Here is a sample deployment diagram for our hypothetical deployment platform:
What the diagram showsOur deployment platform will comprise a backend Windows NT server running a SQL Server database, with the Entities.dll component deployed to this node. There will also be a Windows .NET application server that services Windows 2000 and Windows XP clients. Whether the Forms.dll component and the Controllers.dll component are deployed on the Windows .NET Server or on the clients themselves will depend on our choice of a thin- or fat-client architecture. For the sake of argument, we'll assume these components to be deployed to the Windows .NET Server. In either case, we'll deploy the main OrderProcessingApp.exe executable program directly on the client nodes.
Fitting the Pieces into the UML JigsawAs stated earlier, the problem with many UML books and training courses is that they often present the various diagram types in isolation. To make things worse, the examples are often disjointed and not relevant to any system that you're ever likely to build: a vehicle gearbox as the state diagram example, a telephone handset as the sequence diagram example, an insect classification for the class diagram. All of which leaves you wondering about the relevance of these modeling techniques and the relationships between the various techniques. To address the issues of relevance and consistency of examples you will notice that all of the diagrams in the previous section relate to a common application, the order processing application, which is one that should be familiar to you, whatever your background. Now, what of the relationships between the diagrams that we've alluded to? Well, each diagram shows a different aspect of the same application design so they should be taken, not individually in isolation, but as a consistent whole. The word consistent in that sentence is important because you affect the correctness and completeness of your design significantly by ensuring consistency between the diagrams. The following figure shows how the various diagrams relate to each other at the macroscopic level. The Use Case Diagram represents the functionality requirements of the system from a user's - or a least a system analyst's - perspective. These use cases are realized as the object interactions of a Sequence (or Collaboration) Diagram and the use case participating classes may be represented as a Class (Static Structure) Diagram. For each class that is stateful in nature there may be a State diagram.
Here's the consistency bit, which we've distilled into the following set of rules:
Depending on your approach to analysis and design, and the kind of application you're developing, those rules may be more or less important and you're unlikely ever to achieve 100% mutual consistency. So treat them not as revealed truth but as rules of thumb - I've found that they've certainly served me well in my development work. The fact that the previous figure has arrows emitting from the Use Case Diagram - with none going in - suggests that as the starting point. That's true unless you draw some activity diagrams up-front, and it makes perfect sense to start with the diagram that represents the functional requirements doesn't it? However, the diagram to start with is not really a question of UML but a question of process. We'll conclude this chapter by looking at the process side of things, just after a brief mention of the tools that support the modeling effort.
UML Modeling ToolsIt's doubtful that anyone would be working with UML these days without the aid of a modeling tool, because these tools are to software design what a word processor is to writing. In creating a chapter like this one, few authors would ever dream of writing out the words long-hand with pencil and paper. How would they delete unwanted paragraphs, rephrase sentences and insert the pictures without making the first draft a complete mess? - and how time-consuming would it be to write it all out again for the final draft? Now make the analogy with UML diagrams and a modeling tool. How would you add an operation to a class on a static structure diagram, or change the order of events in a collaboration diagram, or change a relationship between an actor and a use case in a use case diagram without a significant amount of redrawing? At this point, the following question might occur to you:
Wrong! The whole point about a modeling tool is that besides allowing you to draw the diagrams, it actually understands the model you're creating. It knows that a line between two classes is an association or aggregation so an instance of one class must be linked to an instance of another class, perhaps via a member variable. It's this understanding of the model that allows the modeling tool to provide added value to your software development effort through code generation, documentation production, and model semantic checking. Before the arrival of Visual Studio .NET on the software development scene, your choice of modeling tool would most likely have been one of Rational Rose, Select Enterprise, or Together Control Center - none of which cater specifically for UML in the context of .NET. The main contenders in the .NET modeling space are Rational XDE and Visio for Enterprise Architects. Rational XDE has the Rational pedigree, some impressive .NET-related features, and tight integration with Visual Studio .NET; so it's well worth a look if you're from a Rational tools background. The main problem is that you may have to shell out on an expensive license on top of what you've already paid for Visual Studio .NET, and - on that subject - it actually won't run without the IDE. Visio for Enterprise Architects comes bundled with the Visual Studio .NET (Enterprise Architect version) and/or an MSDN Universal Subscription, so you may already have it at no extra cost. It supports UML notation as well as the back-catalogue of other Visio diagram types. Code generation, reverse engineering, model semantic checking, and document production are supported, plus integration with the Visual Studio .NET IDE. All of which make this not just a drawing tool, or - more accurately - no longer just a drawing tool.
| |||||||||||||||||||||||||||||||||||