Examining the UML Models: Static Models - Dependencies
(Page 9 of 13 )
Dependency is a relationship indicating that one element is dependent on another element to function. Say Component1 is dependent on Component2, which means that changes in Component2 will affect Component1, because Component1 uses services or facilities in Component2, and not the other way around.
For example, you might have a component in which some of the classes call a class in another component. Well, why not package all classes in the same component then?12 It defeats the idea of creating unique components that hold only classes that can be grouped because they expose the same kind of functionality. It’s like when you’re at the grocery store; you don’t look for apples in the basket with oranges, do you?
Establishing dependencies has another benefit in that if your component crashes, it will directly affect only one type of functionality. It shouldn’t bring other types of functionality down with it.
In Exercise 5-17, you’ll add a dependency between two components in your component diagram.
EXERCISE 5-17
1. Open MyComponentDiagram.
2. Add a dependency between Component1 and Component2.
In Figure 5-25, you can see that Component1 is dependent on Component2, illustrated by the dependency (dashed line).
Interfaces Of course, you know about your model’s public interfaces by looking at your public functions in the classes. However, if you have a component representing a third-party DLL, you might not know about the public interfaces, because you haven’t modeled the classes and functions. That’s when the interface element of a component diagram can be useful.
Like any class, an interface needs at least one operation, and operations can have parameters. In Figure 5-25, the Imageshrink.dll component represents a COM+ component purchased from an external vendor. The _Imageshrink interface is the COM+ type library. A type library is required to expose the interfaces to users of the component. The interfaces exposed are illustrated as operations on the Interface shape. In Exercise 5-18, you’ll add an interface that has one public operation, Shrink, to your component diagram. This operation will represent a function and have three parameters.
EXERCISE 5-18
- On MyComponentDiagram, add an interface named _Imageshrink to the Imageshrink.dll component. The Interface shape is the lollipop, as shown in Figure 5-25.
- Double-click the _Imageshrink interface to open the UML Interface Properties dialog box.
- Select the Operations category.
- Click New to add a new operation named Shrink, of data type VB::Object (C#::object if you want to code in C#), as shown in Figure 5-27.

Figure 5-27. Operations category of the UML Interface Properties dialog box
5. Click OK.
NOTE You can’t tell from the Model Explorer whether the operation returns a value. You need to open the UML Operation Properties dialog box to get that information.
6. Double-click the _Imageshrink interface to open the UML
Interface Properties dialog box and select the Operations
category again.
7. Select the Shrink operation.
8. Click Properties to open the UML Operation Properties dialog box.
9. Select the Parameters category.
10. Click New to add a new in-going parameter named BMPImage of
data type VB::Object (or C#::object if you want to code in
C#).
11. Click New to add a new in-going parameter named
ShrinkPercentage of data type VB::Integer (or C#::int if you
want to code in C#). Your UML Operation Properties dialog box
should look like Figure 5-28.

Figure 5-28. Parameters category of the UML Operation Properties
dialog box
12. Click OK twice. In Figure 5-29, you can see how the
_Imageshrink interface looks in the Model Explorer.

Figure 5-29. Interface shown in the Model Explorer
NOTE As you can see in the Model Explorer, the
Shrink interface has three parameters:
Shrink, BMPImage, and
ShrinkPercent. What you can’t tell from the Model Explorer is if a parameter is an input or output parameter. You need to open the UML Operation Properties dialog box to see this information.
When developing COM+ components to run in the COM+ runtime environment of Component Services, you need to instantiate the ObjectControl interface of the COM+ runtime environment and add three operations to your component: Activate, Deactivate, and CanBePooled. In Figure 5-30, you can see how the ObjectControl interface could be added to the Imageshrink.dll component in our example. You’ll add the ObjectControl interface in Exercise 5-19, in the next section.

Figure 5-30. COM+ component with the ObjectControl interface
Next: Code Generation from a Component Diagram >>
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.
|
|