Examining the UML Models: Static Models - Stereotypes
(Page 12 of 13 )
We have mentioned stereotypes several times in this chapter and previous chapters. Stereotypes are simply a subtype you specify for a type.
For example, a use case is of the type Use Case. If you then specify the stereotype to be Business Use Case, the use case is still a use case, but it’s a use case of the type Business Use Case. Similarly, you can specify that a class is a Class but also a class of the type struct.
Stereotypes are just a way for you to specify subtypes for your types. The notation for a stereotype is <<stereotype name>>. Stereotypes exist for almost all elements. You can apply the built-in stereotypes provided by VEA or define your own stereotypes, as described in the following sections.
Built-in Stereotypes The built-in stereotypes are predefined by VEA and vary from element type to element type. For example, the struct stereotype is one of the stereotypes available for classes in the UML Class Properties dialog box, as shown in Figure 5-39.

Figure 5-39. Stereotypes in the UML Class Properties dialog box
Figure 5-40 shows the Class1 class with the struct stereotype.

Figure 5-40. Class1 class with the struct stereotype
User-Defined Stereotypes Creating your own stereotypes is useful if you want to specify a stereotype for a commonly used element that is not predefined by VEA. For example, you might want to specify that a class will be implemented as an ASP.NET page. VEA doesn’t have a built-in stereotype to represent an ASP.NET page, but you can easily create one. The only disadvantage of using user-defined stereotypes is that, because VEA doesn’t know about the user-defined stereotypes, they can’t be reflected in the generated code. In other words, it’s a visual thing only.
To create a new stereotype, select UML -> Stereotypes to open the UML Stereotypes dialog box, as shown in Figure 5-41. Then click New. Type the stereotype name in the stereotype field of the new stereotype row, which is created at the top of the Stereotypes list. The important thing to remember is to choose to which base class the new stereotype belongs from the Base Class list; otherwise, it will not be accessible from the Stereotype list for the element.

Figure 5-41. UML Stereotypes dialog box
In Figure 5-42, you can see that the Class1 class has the ASP.NET Page stereotype.

Figure 5-42. Class1 class with the ASP.NET Page stereotype
UML Code Mapping to .NET In this chapter, you’ve learned that some of the UML elements can be mapped directly to the .NET language. In Table 5-1, you can see how some of the UML elements from the structural models map to the .NET language. You’ll need to know about code mapping if you want to generate code from your UML diagrams.
Table 5-1. UML Code Mapping to .NET
| UML Element | VB .NET Code | C# Code |
|---|
| Package | Namespace keyword | namespace keyword |
| Class | Class keyword | class keyword |
| Procedure operation without return parameter (class) | Sub keyword | Prefix procedure name with void keyword |
| Procedure operation with return parameter (class) | Function keyword | This is the default operation, so no keyword or prefix is necessary |
| Destructor operation (class) | Sub Finalize procedure | No keyword is necessary; it has the same name as the class, prefixed with a ~character |
| Constructor operation (class) | Sub New procedure | No keyword is necessary; it has the same name as the class |
| Event operation (class) | Event keyword | event keyword |
| Property operation (class) | Property keyword | property keyword |
| Generalization relation (class) | Inherits | No keyword is necessary; simply add a colon after the class name and then the name of the base class |
| Attribute (class) | Declare as variable | Declare as variable |
| Binary association (with bounded multiplicity and IsNavigable selected) | | Data member (variable) |
| Binary association (with unbounded multiplicity and IsNavigable selected) | | Data member (System.Collections .ArrayList) |
| Abstract operation (class) | MustOverride keyword | abstract keyword |
| Abstract class | MustInherit keyword | abstract keyword |
| Operation (IsPolymorphic) | Overridable keyword | virtual keyword |
| | |
| UML data type with <<ENUM>> stereotype | Enum keyword | enum keyword |
| | |
| UML class with <<STRUCT>> stereotype | Structure keyword | struct keyword |
| | |
| Interface | Interface keyword | interface keyword |
| Attribute (class, with frozen setting set) | Const keyword | const keyword |
| Attribute (multiplicity set to [*]) | Data member (System.Collections .ArrayList) | Data member (System.Collections .ArrayList) |
| Delegate (class with <<DELEGATE>> stereotype) | Delegate keyword | delegate keyword |
| Union (class with <<UNION>> stereotype) | union keyword (C++ Managed Extensions only) | union keyword (C++ Managed Extensions only) |
| Struct (class with <<STRUCT>> stereotype) | struct keyword (C++ Managed Extensions only) | struct keyword (C++ Managed Extensions only) |
Table 5-2 lists the file types you can generate.
Table 5-2. Code File Types
| File Type | File Extension |
C# source file | *.cs |
C++ source file | *.cpp |
Header file | *.h |
VB .NET source file | *.vb |
Next: Summary >>
More .NET Articles
More By Apress Publishing
|
This article is excerpted from Enterprise Development with Visual Studio .NET, UML, and MSF written by John Erik Hansen and Carsten Thomsen (Apress, 2004; ISBN: 1590590422) Buy this book now.
|
|