Поделиться через


Extending UML Models and Diagrams

This topic summarizes the different ways in which you can extend the UML modeling tools of Visual Studio Ultimate.

In the following example scenario, Fabrikam designs and installs airport baggage handling systems. From one airport project to the next, there are many similarities in the basic equipment and the software that controls it. However, there are also several factors that vary widely, such as the configuration of conveyor belts, checkin desks, storage bins, and other bag handling equipment.

When starting a new project, the Fabrikam team creates a UML model to help them discuss these requirements between themselves and with their customer. They use activity diagrams to represent the flow of bags, with object nodes representing each piece of equipment. The UML model does not directly represent the system's code.

Fabrikam's tools team makes a series of enhancements to help the development teams. The following sections describe the different kinds of extensions that you can define. You can combine several of these techniques into one Visual Studio extension. 

Profiles

Profiles let you define stereotypes and additional properties on UML elements.

Fabrikam's tool developers define stereotypes on the object nodes of activity diagrams, such as «conveyor belt» and «checkin desk». When a team member creates a baggage handling scheme using an activity diagram, they can now set stereotypes to indicate what type of equipment each node represents. The tool developers define additional properties on some of the stereotypes, so that users can record values such as the capacity of a conveyor belt, and the handedness of a checkin desk.

For more information, see How to: Define a Profile to Extend UML.

Custom Toolbox Items

A custom toolbox item creates an element or a group of elements from a prototype that you define in a diagram. For example, you could create a tool that creates use cases in a particular color or stereotype, or a group of classes and associations that represents a design pattern. You can add these toolbox items to Visual Studio extensions and distribute them to other users.

For more information, see How to: Define a Custom Modeling Toolbox Item.

Validation

You can define rules to ensure that a UML model conforms to specified constraints.

Fabrikam's tool developers define rules to help team members avoid simple mistakes in baggage handling models. For example, a checkin desk cannot be connected directly to a storage bin. There must at least be a conveyor belt between them.

For more information, see How to: Define Validation Constraints for UML Models.

You can define commands that users can invoke by right-clicking elements on a UML diagram. The commands can update the model and diagrams or perform other operations in Visual Studio.

Fabrikam defines menu commands to automate frequently-performed operations, such as create a check-in desk and connect it to a selected conveyor belt or rearrange a diagram according to the company's layout rules.

See How to: Define a Menu Command on a Modeling Diagram.

Gestures

You can define commands that users initiate by double-clicking a diagram element, or by dragging onto a diagram or an element on the diagram. You can define commands that can deal with items dragged from other UML diagrams, from other parts of Visual Studio, or from other applications or Windows Explorer.

Fabrikam team members can associate a file such as a specification with any model element by dragging it from the Windows desktop. The tool developers defined a stereotype that provides any element with a file path property, and a gesture that sets the stereotype and the file path when a file is dropped onto an element.

For more information, see How to: Define a Drop and Double-Click Handler on a Modeling Diagram.

Responding to Changes

You can write code that responds to changes in the model, whether caused by user actions or by other program code.

Fabrikam’s developers create code that automatically sets the color of an element dependent on its stereotype. This makes it easy for users to distinguish the different roles played by elements in the models.

For more information, see How to: Respond to Changes in a UML Model.

Model Bus

Model Bus allows you to access a diagram or model from another diagram or from another Visual Studio Extension. Among other things, this allows you to spread information across more than one model, so that several people can work on the combined model at the same time.

Fabrikam uses elements on activity diagrams to represent baggage handling equipment. Each item of equipment can have a more detailed specification in another diagram, which can be in another model. The validation constraints on the baggage flow diagram can retrieve relevant properties of the equipment from the other diagrams. The references to the other diagrams are stored in additional properties defined in stereotypes.

For more information, see How to: Integrate UML Models with Other Models and Tools.

Generation

From a model, you can generate program code, scripts, configurations, documents, new models, or other artifacts.

In the baggage systems that Fabrikam designs, much of the program code is the same from one project to the next. The major variable aspect is the plan of the baggage flow around the airport. After the design team has had the experience of their first few projects, the tool developers create a template that generates, from the baggage flow model, much of the variable program code and other files such as user documents. This considerably reduces the development time and error rate for each new project.

For more information, see How to: Generate Files from a UML Model.

Team Foundation Server Integration

You can link work items to model elements, and access the linked items programmatically.

Fabrikam's tool developers write a tool that generates a work schedule for each airport project. The work items in the schedule are linked to the model elements.

For more information, see How to: Define a Work Item Link Handler.

Tools that Update Models

You can create stand-alone applications and Visual Studio extensions that can load UML models.

Fabrikam's developers create a tool that reads a model and generates reports of the progress of work on each element of the model.

For more information, see How to: Read a UML Model in Program Code.

Domain-Specific Languages

Where you frequently use a particular type of model, it can be useful to create a domain-specific language. This can be made to fit your business needs more closely than a UML model, but requires more effort to build it and maintain it. For more information, see Visualization and Modeling SDK - Domain-Specific Languages.

Requirements

External Resources

Category

Links

Videos

link to videoMSDN How Do I Series: UML Tools and Extensibility

link to videoChannel 9: UML with Visual Studio 2010 Ultimate

Forums

Blogs

Visual Studio Architecture, Visualization, and Modeling Tools Blog

Technical Articles and Journals

The Architecture Journal - Issue 23: Architecture Modeling and Processes

Other Sites

MSDN Architecture Center

See Also

Concepts

Developing Models for Software Design

Other Resources

API Reference for UML Modeling Extensibility