Introduction
Unified modeling language (UML) is a system of concepts and notation for abstracting and representing discrete systems, particularly but not exclusively object-oriented software systems. It is widely used as a common notation for describing software systems in publications and design models. Although widely misunderstood as merely a pictorial notation, UML is more importantly a set of modeling concepts that are more general than those contained in most programming languages and widely applicable to real-world discrete systems as well as software systems. UML is “unified” because it combines a number of competing but similar modeling languages that were previously fighting for domination, eventually superseding all or most of them in public usage; “modeling” because its primary intended use is to construct abstract models of discrete systems that can subsequently be converted into a concrete implementation, such as a programming language, database schema, or real-world organization; and a “language” because it comprises both internal structural concepts (metamodel) and an external representation (visual notation). UML supports an engineering-based design approach in which models of software are constructed to understand and organize a system and fix problems before software is written. Although modeling is universally used by engineers, architects, and economists, software personnel have often been reluctant to use modeling despite the large number of errors often found in completed software.
UML comprises a number of loosely connected facets, often called submodel types or (in reference to the visual notation) diagram types. UML is intended to be a general-purpose modeling language, that is, it is applicable to all or at least most kinds of modeling problems. Unlike many academic modeling languages that emphasize elegance, a minimal set of basic concepts, and efficacy in theorem proving, UML is a pragmatic, “messy” modeling language with some redundant concepts and multiple ways of expressing them, similar to most mainline programming languages or natural languages. The various submodel types vary in elegance, level of abstraction, and usefulness. Because different submodel types were proposed and defined by different people as part of a consensus-based development process, they sometimes fit together a little awkwardly, like many major software applications.
UML is informed by object-oriented principles, although it can be used to model nonobject- oriented systems as well. It can be used at various levels of abstraction from very high-level system models to detailed models of programs.
Diagram Types
In this description, the term “diagram type” is used as a shorthand to represent a set of related concepts within a submodel type of UML and their visual notation. The most commonly used UML diagram types include class diagrams, use case diagrams, sequence diagrams, state machine diagrams, and activity diagrams.
Class Diagram
The class diagram is by far the most widely used kind of UML diagram. It describes the concepts within a system and their relationships. It is used to organize the information within a system into classes, understand the behavior of the classes, and generate their data structure. Figure C.1 shows a (much simplified) example of a class diagram showing the kinds of recording requests within a digital video recorder (DVR) system attached to a satellite television receiver.
Figure C.1 Class diagram.
A class is the description of a system concept that can be represented by data structure, behavior, and relationships. For example, “RecordRequest” is a class representing an entry in the DVR list of television shows to be recorded. An individual instance of a class is an object. A class has attributes, each of which describes a data value held by each object that is an instance of the class. For example, a RecordRequest has a numerical priority indicating its urgency if the DVR disk becomes full. Each object has its own particular data values for the attributes of its class, and the values of each object may differ from other objects of the same class. The data values of a single object can vary over time. An attribute includes a name, a data type, and optional constraints on the values that objects of the class may hold. A class can also have operations, each of which describes a behavior that objects of the class can perform. Individual objects do not have distinct operations; all the objects of the same class have the same behavior, which can be implemented by shared code, similar machinery, printed documents, or other ways appropriate to the kind of system.
Classes are shown as rectangles with three sections, some of which may be optionally suppressed in a diagram. The top section shows the name of the class, and the middle section shows a list of attributes in the form “name: type = initial value.”
In the example, the default priority of a record request is 1. The bottom section shows a list of operations in the form “name (parameter-list): returntype.” For example, a new record request can be added to the recording queue, and an existing request can be canceled. Various other indicators may be attached to attributes and operations.
There are two major kinds of relationships among classes: associations and generalizations. Associations are semantic relationships between pairs (or, in general, tuples) of objects. The value of an association is a set of object tuples. Associations are often implemented as pointers within objects (in C, C++, and Java) or as sets or tables of tuples of object identifiers (in SQL and other databases). Modeling associations is of great importance because they are the glue that holds a system together. A binary association, by far the most common kind, is shown as a line between two classes. For example, a show contains episodes. A number near an end of an association line indicates the multiplicity of the association in that direction, that is, how many instances of the class at that end may be associated with any one instance of the class at the other end. The value may be a single number or an integer range. An asterisk represents many instances, that is, zero or more without limit. For example, each show may include many episodes, but each episode belongs to exactly one show. A name can be given to the entire association and to both ends of it. In the example, there is a single unique association between each pair of classes, so the names have been omitted. Various other restrictions can be attached to the association ends.
Generalization is the relationship between a general class and a more specific variety of it. The general class (superclass) can be specialized to yield one of several specific classes (subclasses). This has several benefits. The data structure and behavior of the superclass can be inherited by each subclass without the need for repetition. Most importantly, an operation in a superclass can be defined without an implementation, with the understanding that an implementation will be eventually supplied by every subclass. This is called polymorphism, because the abstract operation takes on a different concrete form in each subclass. A class lacking implementations for one or more operations is an abstract class; it cannot be instantiated directly, but it can serve as a data type declaration for variables that can be bound to objects of any subclass. This means that operations can be written in terms of abstract classes, with the actual implementations dependent on the actual object types at run time. It also permits collections of objects of mixed subclasses to be freely manipulated; the operation implementation appropriate to each object in the collection is determined dynamically at run time.
Generalization is shown as a line between classes with a large triangle attached to the more general class. A group of common subclasses can be shown as a tree sharing a single triangle to the superclass. In the example, RecordRequest is a superclass of “RecordEpisode” and “RecordSeries.” This indicates that a request for a recording may either indicate a single episode or all the episodes of a given series. Both RecordEpisode and RecordSeries inherit the attribute (“Priority”) and operations (“Add” and “Cancel”) from the superclass RecordRequest. The main advantage of inheritance is that subsequent changes to the superclass, such as the addition of new attributes or operations, are automatically incorporated in the subclasses.
From the example, we see that a series recording request can be indirectly related to a set of episodes. This might suggest that the implementation of the internal recording mechanism needs only to deal with episodes. The relationship between episodes and shows can be maintained within the request queue. Class diagrams permit this kind of analysis to be made quickly.
Several other kinds of relationships such as various kinds of dependencies and the derivation of certain attributes from others are less frequently used.
Use Case Diagram
A use case diagram shows the externally visible behavior of a system as it might be perceived by a user of the system. Such users can include humans, physical systems, and software systems. The diagram is used to factor and organizes the high-level behavior of a system into meaningful units during early design, but detailed implementation is usually referred to other, more specific models, such as activity diagrams or collaboration diagrams; Figure C.2 shows a use case diagram for a DVR (again, much simplified).
Figure C.2 Use case diagram.
An actor represents a set of external users playing a similar role in interacting with the system being modeled. For example, actors that interact with the DVR are the viewer and the network. A use case represents a meaningful unit of behavior performed by the modeled system for the benefit of or at the request of a particular actor. For example, the viewer can request a recording, play an existing recording, and buy a pay-per-view show. (A real DVR would have a number of additional use cases that would make the example too large.) The network is involved in the “BuyShow” use case initiated by the user and also participates in the “DownloadGuide” use case, which represents downloading the program guide periodically in the background without the involvement of the viewer. The granularity of a use case is somewhat subjective, but it should be large enough to be meaningful to the actor, rather than trying to capture the implementation of the system.
For example, it is not appropriate to include minor user interface actions such as paging through the program guide, selecting a show, and specifying the recording parameters as separate use cases; these are best modeled as details of the user interface that implement the use case. The purpose of enumerating use cases is to capture the externally visible behavior of a system at a high level.
The target system or class is shown as a rectangle containing a set of use cases, each shown as an ellipse containing the name of the use case. In the example, the main focus is the DVR, its use cases, and the objects that communicate with it directly. An actor is shown as a stick person outside the bounds of the system rectangle. In the example, the viewer and network are actors with respect to the DVR. A line connecting an actor to a use case shows the association between the actor and the use case in which it participates. Each actor can participate in multiple use cases, and each use case can interact with multiple actors. Details of the actors themselves are not included in the use case diagram; the focus of the use case diagram is the behavior of the target class, in this case the DVR. If some of the actors are also systems, they might have their own use case diagrams.
Various relationships among use cases can be shown, such as generalization and the inclusion of one use case as a part of another.
The use case diagram does not contain a great deal of detailed information. It is primarily of use in the early stages of design to organize the system requirements, particularly from a user viewpoint. The behavior of a use case can be documented using sequence diagrams, activity diagrams, or, in most cases, simple text descriptions.
Sequence Diagram
A sequence diagram shows an interaction among two or more participants as a set of time-sequenced messages among the participants. The main focus is the relative sequence of messages, rather than the exact timing. It is used to identify and describe typical as well as exceptional interactions to ensure that system behavior is accurate and complete. Sequence diagrams are particularly useful for interactions among more than two participants, as two-party conversations are easily shown as simple text dialogs alternating between the two parties. Figure C.3 shows an example of a sequence diagram for viewing a live show using the DVR.
Figure C.3 Sequence diagram.
A sequence diagram involves two or more roles, that is, objects that participate in the interaction. Their names (and optionally types) are shown in small boxes at the top of the diagram, with vertical lines (lifelines) showing their lifetime in the system. The example shows three roles: the viewer, the DVR, and the satellite network. In this example, all three objects exist for the duration of the interaction; therefore, their lifelines traverse the entire diagram.
A message is a single one-way communication from one object to another. A message is shown as a horizontal line between lifelines with an arrowhead attached to the receiving lifeline. The name of the message is placed near the line. In a more detailed diagram, the parameters of the messages can be shown. The example begins when the viewer requests to see the program guide, which the DVR then displays. The viewer may ask to scroll the guide, which the DVR redisplays. This subsequence is placed inside a “loop” box to show that it may be repeated. The viewer then requests to view a show. In this example, the show happens to be a pay-per-view show, so the DVR asks the viewer whether the viewer wants to buy the show. The user does buy the show, so the DVR submits the request to the network. The example shows two possible outcomes in the two sections of the alt (for “alternative”) box: If the purchase is successful, the network sends an authorization and the DVR displays the shows; if the purchase fails (maybe the viewer’s credit limit has been exceeded), an error message is displayed. Although a sequence diagram can display closely related alternatives, it is not intended to show all possible interactions. It is meant to show typical interaction sequences to help users understand what a system will do and to help developers think about possible interactions among features. Instead of trying to show everything on a single sequence diagram, a model should include multiple sequence diagrams to represent variant interactions. It is particularly important to include at least one sequence diagram for every possible error condition or exception that can occur.
State Machine Diagram
A state machine diagram shows the states that an object (often a system) can assume and the transitions that move the object among states in response to various events that the object may perceive. It is used to identify and structure the control aspect of system behavior. Simple state machines have been important in electrical engineering and computing for many decades. UML uses an enhanced version of state machines based on the work of David Harel, which allows grouping of states into higher-level states. This is a kind of generalization of states that avoids the repetition of the same transition in many low-level states. State machine diagrams are useful for traditional control applications as well as for understanding the life history of objects.
Figure C.4 shows an example of a state machine diagram showing the life history of a recording request in the DVR. The same state machine is applicable to every recording request. Many recording requests can exist simultaneously, and each has its own distinct state.
Figure C.4 State machine diagram.
A state is shown as a rounded rectangle containing the name of the state. For example, the “Queued” state means that a recording request has been created, but the start time of the show has not yet arrived. A transition is shown as an arrow from a source state to a target state. The transition is labeled with the name of an event that may occur during the source state and, optionally, with a slash (/) character followed by an action. If an event occurs when an object is in a state that is the source state for a transition for that event, the action on the transition is performed and the object assumes the target state specified by the transition. For example, if the start time of a show arrives while a recording request is in the Queued state, the DVR starts recording, and the recording request assumes the “Recording” state. That state in turn lasts until the stop time of the show arrives, after which the recording ceases and the recording request assumes the “Saved” state.
The creation of an object is shown by a small black disk. The disk is connected by a transition to the initial state of the object; the transition may also specify an initial action. For example, when a recording request is created, a list item is allocated for it and it assumes the Queued state.
The destruction of an object is shown by a small bull’s eye. If a transition causes the object to reach this state, any action on the transition is performed and the object is destroyed. For example, if the “Delete” event occurs while a recording request is in the Recording state, the memory for the recording is deallocated and the request is destroyed; if it occurs in the “Queued” state, no recording has yet occurred, so the request is just destroyed.
The full version of state diagrams supports concurrent states. The state of an object can have two or more separate parts, each of which progresses independently. For example, a more elaborate version of the DVR state machine diagram would show the ability both to record a show and to play an earlier portion of the recording simultaneously. Although the concurrent states are mostly independent, they can have some dependencies. For example, if the viewer fast-forwards the playback of the recording so that it catches up with the live recording, the viewer cannot jump forward any more.
Substates are also supported by nesting substates within superstates. For example, the Delete event could be attached to a single transition on a high-level superstate containing multiple detailed substates. If the event occurs during any of the detailed substates, the high-level transition would take precedence. The ability to apply a single transition to many nested substates is particularly useful for exception conditions and forced exits, because it becomes unnecessary to attach the error handling to each nested substate explicitly.
Activity Diagram
An activity diagram shows the sequencing of actions within an overall process. In general, it includes concurrent processes as well as sequential processes, so it has the form of a directed graph rather than a simple chain. This diagram is used to understand the control and data dependencies among the various pieces of detailed behavior that compose a high-level system behavior, to ensure that the overall behavior is adequately covered and that detailed behaviors are performed in the correct orders.
The sample activity diagram in Figure C.5 shows the process of changing a channel on the DVR. An activity diagram can be divided into multiple columns, each showing the actions performed by one of the participants. The participants in this example are the viewer, the DVR program guide, and the satellite receiver subsystem. An action is shown as a rounded rectangle. This is the same symbol as a state in a state diagram because an action is a state of a process. A decision is shown as a diamond with two or more outgoing arrows, each labeled by a condition. An arrow shows a temporal dependency between two actions; the first must be completed to enable the second. Synchronization is shown by a heavy bar with two or more inputs or outputs; a synchronization bar initiates or terminates concurrent actions.
Figure C.5 Activity diagram.
In the example, initially the viewer selects a channel. This triggers the program guide subsystem to determine if the viewer subscribes to the channel and if it is currently broadcasting. If the channel is not available, the viewer receives an error message. If the channel is available, the receiver must perform three concurrent actions to display the channel, as shown by the synchronization bar followed by arrows to three concurrent actions. The decision performed by the program guide enables the three concurrent actions: tuning the receiver, selecting the correct satellite input, and setting the television format to low or high definition. The initiation of concurrent activity is called a fork. Once concurrent actions are enabled, they proceed independently until a subsequent synchronization bar joins them back together. When all three actions are complete, the synchronization bar on the bottom is triggered, which triggers the guide unit to start recording the current channel. The synchronization of concurrent activity is called a join. Finally, the user is allowed to view the channel.
In the complete version of activity diagrams, conditional and iterative behavior may be represented, as well as more complicated kinds of synchronization.
Activity diagrams can be used to plan implementations of operations. They are also useful for modeling business processes.
Other Diagram Types
UML has several other diagram types that are not illustrated in this entry. See the references for more details.
Some of the most important types are briefly described later in the entry.
Internal Structure Diagram
An internal structure diagram is a variant on the class diagram that shows the internal structure of an object in terms of its constituent parts and their relationships to each other and to ports connecting the object to the external world. This diagram type is used for hierarchical design, in which an external view of a class at one level is expanded into a particular realization or internal implementation at the next lower level. This is a more recent important addition to UML that bridges the gap between hierarchical specification and implementation more effectively than simple class diagrams, although widespread adoption has been slow.
Collaboration Diagram
A collaboration diagram shows a collaboration. A collaboration is a contextual relationship among a set of objects, each of which plays a particular role within the collaboration. For example, a dinner party is a collaboration in which roles might include host, guest, and server. A collaboration has structure and behavior. This diagram is used to understand the specific behavior of objects in a contextual relationship, as opposed to behavior inherent to an object in any context because of its class.
Communication Diagram
A communication diagram shows a sequence of messages imposed on the data structure that implements the system. It combines aspects of sequence diagrams and internal structure diagrams in a rich form that is, however, more difficult to perceive. It is useful for designing algorithms and code provided excessive low-level detail is avoided.
Deployment Diagram
A deployment diagram shows the physical implementation elements of a system, including the physical execution nodes and the software artifacts stored on them. This diagram type lacks the detail of some other diagram types and is not very concise; therefore, it is not among the most successful UML diagram types.
Package Diagram
A package diagram shows the organization of a software system into design and compilation packages, including nested packages and their dependencies. It is used to organize a model into working units and to understand the effects of changes on the overall system.
Profiles
UML is a large general-purpose modeling language, but frequently the full power of UML is not needed in a particular usage. At the same time, sometimes a model builder wants to adopt more stringent assumptions than those made by the full UML, which must accommodate a wide range of uses. A UML profile is intended for this kind of usage. For example, UML in general assumes full concurrency, but a profile for a sequential application domain might remove this assumption to simplify modeling within that domain.
A profile is a named, specified subset of UML together with a limited set of additions and constraints that fit the profile for a particular area of usage. Profiles are often constructed and supported by standardization workgroups responsible for a particular application domain. They provide a way to adapt UML to a particular application area rather than constructing a new complete modeling language.
Because profiles are layered on standard UML using a limited set of extension mechanisms, they can be constructed and maintained by general-purpose UML modeling tools.
A lot of modeling energy has gone into the construction of profiles. These include profiles for various programming languages, database schemas, system engineering, real-time systems, and a wide variety of application domains.
Usage
UML can be used in many different ways for different purposes. One advantage of using UML rather than specialized languages for various domains is that most real-world applications include subsystems of many different kinds, and most specialized languages are somewhat restrictive in their scope, leading to problems in combining models built using different languages. A number of commercial and open-source tools support editing of UML models; the tools vary widely in completeness and other features, such as support for code generation.
Programming Design
UML can be used to perform the high-level design of software systems by first capturing requirements using class diagrams, use case diagrams, and sequence diagrams. The class diagrams can be elaborated to design classes that will be implemented in programming languages. Package diagrams can help to organize the structure of the program units.
Programming Detail
Detailed class diagrams can be used to generate class declarations in languages such as C ++ and Java. A number of commercial software design tools can perform this kind of code generation. Specification of algorithms can be done using activity diagrams and state machine diagrams, although these can sometimes be as expansive as the final code. Code generation using patterns can produce a significant amplification of detail and may be the most productive use of modeling to generate code.
Database Design
Class diagrams can model the information to be represented within a database. A number of UML extensions have added database features (such as keys and indexes) to basic UML. The database community has been somewhat wary of UML, however, often preferring to use older modeling languages explicitly designed for databases, but often lacking in expressiveness. One advantage of using UML is that both database schemas and programming language class declarations can be generated from the same information, reducing the danger of inconsistency.
Business Process Design
Activity diagrams are good for modeling business processes. Class diagrams can model the data implicit in business processes, usually with more power than traditional business modeling languages.
Embedded Control
State machine diagrams can represent the control aspects of a real-time system, but class diagrams and internal structure diagrams can also represent the data structures that the system uses.
Application Requirements
Use case diagrams can capture the high-level functionality of a system. Class diagrams can capture the information in a particular application domain. These can then be elaborated to produce a more detailed design model.
UML History
Modeling languages for various purposes dates to at least the early 1970s. Although some were widely used in specific application domains, such as telephone switching systems, none achieved widespread general usage. In the early 1990s, a handful of object-oriented modeling languages developed for general use gained some popularity with no single language being dominant. These languages incorporated ideas from various earlier modeling languages but added an object-oriented spin. The first version of UML was created in 1995 by James Rumbaugh and Grady Booch by uniting their object modeling technique (OMT) and Booch methods. The bulk of that union still forms the core of UML, including the class diagram, the state machine diagram (including Harel’s concepts), the sequence diagram (subsequently much extended with ideas from message sequence charts), and the use case diagram of Jacobson. Subsequent contributions by Ivar Jacobson and a team of submitters from a number of companies resulted in the standardization of UML 1.0 by the Object Management Group (OMG) in 1997. The rights and trademarks to UML were then transferred to the OMG. OMG committees generated several minor updates to UML and a major update to UML 2.0 in 2004 that added profiles and several new diagram types, including internal structure diagrams and collaboration diagrams. OMG continues to maintain the standard. The complete standard and information on standardization activities can be found on their Web site at http:// www.omg.org by following links to UML.
Assessment
UML has achieved its goal of uniting and replacing the multitude of object-oriented modeling languages that preceded it. It is frequently used in the literature to document software designs. It has been less successful in penetrating the practices of average programmers. Partly this is due to the misperception that UML is primarily just a notation, whereas its main purpose is to supply a common set of abstract concepts useful for modeling most kinds of discrete systems. Another factor, however, is that the various parts of UML are widely uneven in quality, approachability, and detail. Some parts, such as class diagrams, are widely used, whereas others, such as deployment diagrams, fail to live up to their promise. One problem is that the committee process of an organization such as the OMG encourages messy compromises, redundancy, and uneven work at the expense of cohesion. There is also an unresolved tension in what the modeling language should be, from an elegant and minimal theoretical basis at one extreme to a “programming through pictures” tool at the other extreme, with the more useful abstract modeling language somewhere in the middle. The tension about what UML should be has worked itself out differently in different submodel types and even in various parts of the same submodel type, which can lead to confusion and uneven coverage of modeling. To its credit, UML is a universal language with features to support a wide range of systems. Such languages, including practical programming languages, must be large and messy to some extent if they are to be used by a wide range of users on a wide range of problems. UML would undoubtedly benefit from a serious trimming of redundant and less successful concepts, but whether that can occur within the limits of a community process is doubtful. UML will probably remain a useful but far-from-perfect tool, but the window for a more coherent modeling language may well be closed.
Further Reading
See the OMG Web site for a detailed specification of UML (UML Specification), including the latest additions to the standard as well as ongoing standardization activity. The UML Reference Manual ( Rumbaugh et al. 2005 ) provides the most coherent detailed reference to UML, more highly organized than the highly detailed standard documents. The UML User Guide ( Booch et al. 2005 ) provides an introduction to UML organized by diagram type. UML Distilled ( Fowler 2004 ) is a brief and highly selective introduction to the parts of UML that its author feels are most important, including some overall suggestions on a recommended design approach. Many other books describe UML either in whole or focused on particular usages.
References
- Booch, G., Rumbaugh, J., & Jacobson, I. (2005). The Unified Modeling Language User Guide , 2nd edition. Addison-Wesley, Boston, MA.
- Fowler, M. (2004). UML Distilled: A Brief Guide to the Standard Object Modeling Language , 3rd edition. Addison-Wesley, Boston, MA.
- Rumbaugh, J., Jacobson, I., & Booch, G. (2005). The Unified Modeling Language Reference Manual , 2nd edition. Addison-Wesley, Boston, MA.
- UML Specification. http://www.uml.org (accessed January 2022)