Examining the UML Models: Static Models
(Page 1 of 13 )
Have you ever wanted to learn more about the structural diagrams used in UML? This article discusses four important types. It is excerpted from
Enterprise Development in Visual Studio.NET, UML, and MSF, by John Erik Hansen and Carsten Thomsen (Apress, 2004; ISBN 1590590422).
IN THIS CHAPTER, we'll introduce you to the UML diagrams known as structural diagrams, which describe the structure (static structure) of your solution. The following UML diagrams are structural diagrams:
- Class diagram
- Statechart diagram
- Component diagram
- Deployment diagram
As in Chapter 4, we’ll describe the frequently used diagrams in detail and use VEA 2003 for the exercises. These exercises are simple, yet they do teach you how to work with the UML models in VEA. Do yourself a favor and follow the exercises, especially if you’re new to UML and/or VEA.
In this chapter, you’ll see the code generation, which you didn’t see in Chapter 4. The reason for this is that all code generation is based on the static structure diagrams (class diagrams).1 You’ll also learn about stereotypes, which are basically a way to extend the UML specification by making a subtype appear as an ordinary element. At the end of the chapter, we’ll show you how .NET code maps to UML.
Class Diagrams The class diagram is the most essential part of UML modeling, because you determine in your class diagram how the (static) structure of your solution should look, modeled at the most detailed level. In your class diagram, you can see which classes, COM+ components, ASP pages, and so on will be implemented and how they interact with each other. COM+ components, ASP pages, and so on are simply classes with another stereotype, as you’ll learn in this chapter.
When the developers develop the solution, their main source of information is the class diagram. The class diagram provides developers with detailed information about what operation code to develop, along with information about data types, parameters, and namespaces. If the developers need some supporting information about the behavior of the solution, they will look at the behavioral diagrams, such as the sequence diagrams and activity diagrams.
Another reason why class diagrams are the most important part of your UML modeling is that you can generate code only from your static structure diagrams, and your class diagrams are the only diagram type from which you’ll have a code skeleton for ready use in VS .NET.2 Class diagrams basically consist of the following elements:
- Packages
- Classes
- Relationships
We’ll look at each of these elements in the following sections.
Packages
You’ve already been introduced to packages in Chapter 4. Packages can relate to different issues, depending on which diagram are implemented. For class diagrams, a package has two functions:
- A package can be created to group related elements. This can be very useful if you want to form a general view of the model.
- A package can represent a namespace.
In Exercise 5-1, you’ll create a class diagram named MyClassDiagram with a package named MyNamespace, as shown in Figure 5-1.
Figure 5-1. Class diagram with a namespace (package)
EXERCISE 5-1
- Open VEA, if it is not already open.
- Create a class diagram named MyClassDiagram.
- Create a package named MyNamespace.
- Drag a class to the MyClassDiagram diagram and name this class Customer.
- Drag the Customer class in the Model Explorer window onto the MyNamespace package. Notice that the Customer class placed on the MyClassDiagram diagram now has the Namespace specification attached.
NOTE We’ve noticed a bug in VEA: If you create a package in an empty model, the package classifier might not show on the class. To solve this problem, create a new package and delete the first one.
6. You can generate the code for the class and namespace by
selecting UML -> Code -> Generate. In the Generate dialog box,
choose Visual Basic as the target language, check the Customer
check box, and specify the path
as\EDWVSNETUMLMSF\Chapter05\, as shown in Figure 5-2.
Click OK.

Figure 5-2. Generate dialog box with the Customer class
7. VEA now generates the file \EDWVSNETUMLMSF\Chapter 05\
TopPackage\MyNamespace\Customer.vb, containing the code
shown in Figure 5-3. Double-click to open the file in VS .NET.

Figure 5-3. VB.NET code generated for the Customer class
Figure 5-4 shows the code for the Customer class generated with C# as the target language.

Figure 5-4. C# code generated for the Customer class
As you might have noticed, Package shapes are located in the Model Explorer window as well. You can see the MyNamespace package and the Top Package. As you learned in Chapter 4, the global namespace is the global package, and it is named Top Package by default. You’re allowed to have multiple nested packages. To nest a package, just drag a Package shape under another Package shape in the Model Explorer window. (In Chapter 12, you’ll learn what the other Package shapes in the Model Explorer window represent.)
Next: Classes >>
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.
|
|