Examining the UML Models: Static Models - EXERCISE 5-4
(Page 3 of 13 )
- Open the UML Class Properties dialog box for the Customer class by double-clicking the class.
- Select the Operations category.
- Select the GetList operation.
4. Click Properties to open the UML Operation Properties dialog box,
as shown in Figure 5-9.

Figure 5-9. UML Operation Properties dialog box
5. Select the Parameters category.
6. Click New to create a new parameter customerTypeID of data
type VB::Integer (C#::int if you want to code in C#). Set the
Kind to in, for in-going (read-only), as shown in Figure 5-10.

Figure 5-10. UML Operation Properties dialog box with the customerType ID parameter
7. Click OK twice.
Setting the parameter Kind to in indicates that it’s an in-going (read-only) parameter. When generating code for this class, you want this operation to be a method. You can tell VEA that the code generation engine must create this operation as a procedure (method) through the Code Generation Options of the UML Operation Properties dialog box. Exercise 5-5 shows how to make sure GetList is a method.
EXERCISE 5-5
- Open the UML Class Properties dialog box for the Customer class by double-clicking the class.
- Select the Operations category.
- Select the GetList 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#, if you prefer) from the Target language list.
- Select Procedure from the Kind list. Your code generation settings should look like Figure 5-11.

Figure 5-11. UML Operation Properties dialog box with code generation settings
8. Click OK twice.
9. Click the Preview code button to see what the generated code
will look like, as shown in Figure 5-12. If you choose C# as the
target language, the code generation preview will look like the
code shown in Figure 5-13.

Figure 5-12. Code preview for the GetListoperation (VB code)

Figure 5-13. Code for the GetList operation (C# code)
The operation will be generated as a public Function4 procedure, because you’ve specified that the procedure has a return value (it will be generated as a Sub5 procedure if it doesn’t return anything).
CustomerStatus is an operation showing the customer’s online status. This operation will be a property of the class. To make sure the code generation engine generates it as a property, you can specify this in the UML Operation Properties dialog box. You’ll do this in Exercise 5-6.
EXERCISE 5-6
- Open the UML Class Properties dialog box for the Customer class by double-clicking the class.
- Select the Operations category.
- Select the CustomerStatus 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#, if you prefer) from the Target language list.
- Select Property from the Kind list.
- Check the Create Get Method option. Your dialog box should look like Figure 5-14.
- Click OK twice.
- Click the Preview code button to see the code shown in Figure 5-15.

Figure 5-14. UML Operation Properties dialog box for the CustomerStatus operation

Figure 5-15. Code Preview for the CustomerStatus operation (VB code)
In the UML Operation Properties dialog box (Figure 5-14), you can choose if you want to create Set or Get methods. A Set method allows you to set the property, and a Get method allows you to get/read the property. This particular property should be read-only, so you just need to check the Create Get Method option.
As you learned earlier, operations can also be of type constructor or destructor. A constructor is responsible for setting an object to its initial state. In other words, a constructor is a method that is called when the object is created. (Class instantiation is another term for this.) In VB, the constructor is named New. Although you can call the operation anything you like in VEA, the constructor will always be called New, once the code is generated,6 so you might as well call it New in the first place, if you’re working with VB code. As noted earlier, in C#, a constructor is named after the class. In Exercise 5-7, you’ll specify that the New operation is a constructor.
Next: EXERCISE 5-7 >>
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.
|
|