Team LiB   Previous Section   Next Section

9.2 Stereotypes

A stereotype defines a new type of modeling element in the UML. Use stereotypes to define a new type of modeling element and then apply the definition. For example, you might define the concept of a project and the relationship between the project and the things that make up that project.

9.2.1 Defining Stereotypes

In the UML, you create a stereotype definition by showing a class representing the stereotype with a dependency on another class representing the type of modeling element the stereotype represents. The class representing the new type of modeling element and the dependency are marked with the stereotype keyword, and the class representing the type of modeling element to which the stereotype applies is marked with the metaclass keyword. Each class is shown as a solid-outline rectangle marked with the keyword enclosed in guillemets («») or double-angle brackets, before or above its name. The dependency is shown as a dashed arrow from the class representing the stereotype to the other class representing the type of modeling element to which the stereotype applies.

As I discussed in the beginning of this chapter, rather than have many different efforts relating to a project management system define the concept of a project, I can extend the UML to incorporate a definition of what a project is, which may be reused by all these other efforts. Rather than have many different efforts relating to a project management system define the relationship between a project and the things that make up a project, I can extend the UML to incorporate a definition of a relationship between a project and the things that make up a project, which may be reused by all these other efforts. Figure 9-1, a class diagram, defines the concept of a project as a Project stereotype, and defines the relationship between a project and the things that make up a project as a Made Of stereotype. The Class metaclass indicates that the Project stereotype applies to classes, and the Association metaclass indicates that the Made Of stereotype applies to associations.

Figure 9-1. Defining stereotypes
figs/Luml_0901.gif

9.2.2 Applying Stereotypes

In the UML, you apply a stereotype definition to a model element, then call a stereotyped element by showing the name of the new type enclosed in guillemets («») or double-angle brackets, before or above the name of the model element.

Now that I have extended the UML with the concept of a project and the relationship between a project and the things that make it up, I can apply these stereotypes. Figure 9-2, a class diagram, applies the stereotypes defined in Figure 9-1 and shows a development project type named Development Project, and an infrastructure project type named Infrastructure Project. A development project requires and is made of a development environment, which is described using the Development Environment class. An infrastructure project and is made of a deployment environment or platform, which is described using the Deployment Environment class. The Development Project and Infrastructure Project are stereotyped using the Project stereotype, and their relationships are stereotyped using the Made Of stereotype.

Figure 9-2. Applying stereotypes using class diagrams
figs/Luml_0902.gif

Figure 9-3, an object diagram, applies the stereotypes defined in Figure 9-1, together with the classes and associations defined in Figure 9-2, and shows a development project named Proj Mngmnt Sys (which is concerned with developing a project management system), and an infrastructure project named Java Deployment (which is concerned with deploying a Java runtime environment). The Proj Mngmnt Sys development project is made of the Java Dev Env development environment, which provides all the Java tools for developing the project management system. The Java Deployment infrastructure project is made of the UNIX Env deployment environment, which provides the infrastructure or platform for the Java runtime environment. The objects and links are marked with the same stereotypes as their classes and associations, respectively.

Figure 9-3. Applying stereotypes using object diagrams
figs/Luml_0903.gif
    Team LiB   Previous Section   Next Section