Examining the UML Models: Static Models - Code Generation from a Component Diagram
(Page 10 of 13 )
If you generate code from your component diagram alone, you can generate code for only the interfaces, not the components. This is very logical if you think about it, because the components on your component diagram just represent the physical file containing the classes and interfaces.
To generate code for your interfaces, select UML -> Code -> Generate. You can choose which model elements to generate code for from the Generate dialog box. Figure 5-31 shows the Generate dialog box set for generating code for the _Imageshrink interface to the \EDWVSNETUMLMSF\Chapter 05\ path.
After clicking OK in the Generate dialog box, you can open the code file in VS .NET (or any text editor, like Notepad, for that matter) from the path you’ve just specified. Figure 5-32 shows the _Imageshrink.vb file generated for the _Imageshrink interface using the settings in Figure 5-31.

Figure 5-31. Generate dialog box with the _ImageShrink interface selected

Figure 5-32. VB code generated for the _Imageshrink interface
However, generating code for interfaces alone doesn’t make much sense if your interface is connected to one of your own classes. It’s more relevant to generate code for the class that incorporates the interface. In Exercise 5-19, you’ll create a new class diagram with the Class1 class and incorporate the _ImageShrink and ObjectControl interfaces described in the previous section. Then you’ll generate the code for that class.
EXERCISE 5-19
1. In VEA, create a class diagram named ClassInterfaceDiagram.
2. Add a class named Class1 to the diagram.
3. Add the _Imageshrink interface to the diagram, attaching it to
Class1. You can copy the interface from the
MyComponentDiagram diagram you created in the previous
exercises.
4. Add an interface named ObjectControl to Class1.
5. Double-click the ObjectControl interface to open the UML
Interface Properties dialog box, and then select the Operations
category.
6. Add three operations to the ObjectControl interface named
Activate, Deactivate, and CanBePooled. (See Exercise 5-
18 for instructions on how to add the operations.) Your diagram
should now look like Figure 5-33. 
Figure 5-33. Class diagram with Class1 class incorporating the ObjectControl and _imageshrink interfaces
7. Double-click Class1 to see its properties, as shown in Figure 5-
34. As you can see, Class1 doesn’t have any operations. All the
operations shown in Figure 5-33 are implemented from the
interfaces. Click Cancel to close the dialog box.
8. Select UML -> Code -> Generate. In the Generate dialog box,
select only Class1 in the tree view, and then click OK. Your
generated code will look like the code in Figure 5-35.

Figure 5-34. UML Class Properties dialog box for Class1, showing the class does not have any operations

Figure 5-35. Code generated for class1 including interfaces
as you can see, the code listed in Figure 5-35 makes more sense than the code listed in Figure 5-32. The code in Figure 5-35 shows how the class implements the interfaces and that the Shrink operation is automatically generated.
Deployment Diagrams The component diagram shows how the components are physically grouped and implemented. A deployment diagram takes this a step further and shows how the hardware and software elements of your solution will be configured and implemented. You can see how your components will be implemented in the runtime environment. As a rule of thumb, each UML model should contain only a single deployment diagram showing how the solution will look like from a runtime point of view.
A deployment diagram basically consists of three elements:
- Nodes
- Components
- Relationships
Figure 5-36 shows elements in a deployment diagram, as discussed in the following sections.

Figure 5-36. Deployment diagram with two different node types
Next: Nodes >>
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.
|
|