Examining the UML Models: Static Models - EXERCISE 5-7
(Page 4 of 13 )
- Open the UML Class Properties dialog box for the Customer class by double-clicking the class.
- Select the Operations category.
- Select the New operation.
- Click Properties to open the UML Operation Properties dialog box (see Figure 5-9).
- Select the Code Generation Options category.
- Select Visual Basic (or C#) from the Target language list.
- Select Constructor from the Kind list.
- Click OK twice.
- Click the Preview code button to see the code shown in Figure 5-16.

Figure 5-16. Code preview for the New constructor (VB code)
A destructor operation is called when the class is destroyed. Well, at least in theory; it might not be called, depending on how the object was disposed of. In VB, the destructor will be generated as a method with the name Finalize. If you’re working with C#, it will be named after the class. In Exercise 5-8, you’ll specify that the Finalize operation is a destructor.7
EXERCISE 5-8
- Open the UML Class Properties dialog box for the Customer class by double-clicking the class.
- Select the Operations category.
- Select the Finalize operation.
- Click Properties to open the UML Operation Properties dialog box (see Figure 5-9).
5. Select the Code Generation Options category.
6. Select Visual Basic (or C#) from the Target language list.
7. Select Destructor from the Kind list.
8. Click OK twice.
9. Click the Preview code button to see the code shown in Figure
5-17.

Figure 5-17. Code preview for the Finalize destructor (VB code)
Notice in Figure 5-17 how the Overrides keyword is automatically added to the operation signature, because the operation is a destructor. All .NET Framework classes inherit from the Object base class, which has an overridable destructor, so you must override it; you cannot shadow it.8
NOTE Please see your .NET Framework documentation for more information about the Finalize method, destructors, and garbage collection.
Listing 5-1 shows the complete code generated for the Customer class. To generate the code, select UML -> Code -> Generate. In the Generate dialog box (shown earlier in Figure 5-2), choose Visual Basic as the target language, select the Customer option, specify the path as \EDWVSNETUMLMSF\Chapter 05\, and click OK.
Listing 5-1. Code Generated for the Customer Class
1 Namespace MyNamespace
2
3 Public Class Customer
4
5 Public Name As String
6
7 Public Address As String
8
9 Public Function GetList (ByVal customerTypeID As
Integer) As Object
10
11 End Function
12
13 Public ReadOnly Property CustomerStatus () As Boolean
14 Get
15
16 End Get
17
18 End Property
19
20 Public Sub New ()
21
22 End Sub
23
24 Protected Overrides Sub Finalize ()
25
26 End Sub
27
28 End Class
29
30 End Namespace
Now that you’ve seen how the packages and classes elements of class diagrams work, we’ll look at the final element of these diagrams: relationships.
Next: Relationships >>
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.
|
|