温湿度采集系统C#
explicit operator. Such a UML operation should specify the target type of the conversion as the return type and the source or input type of the conversion as a parameter type.
Figure 2 shows an examples for modeling C# unary, binary, and conversion operators. The unary operator ++ takes a parameter of type Point and returns a Point. The binary operator != takes two parameters each of type Point and returns a bool type. The implicit conversion operator is defined, which converts a Point type to int.
Figure 2. C# unary, binary, and conversion operators
Part 3.Modeling properties
A C# property is modeled as a UML property (either a UML attribute or an association end) along with a <<CSharp Property>> stereotype. The UML property should have the same name and type as its corresponding C# property. Modifiers for a C# property are available as Boolean stereotype properties. For example, abstract, virtual, extern, and override are available in the <<CSharp Property>> stereotype properties.
In addition to the modifiers, the stereotype has a property called accessors that which can be set to one of the following values: read-only, write-only or read & write. The read-only value should be used whenever the corresponding C# property has only the get accessor method. Similarly, write-only should be used whenever the corresponding C# property has only set accessor. When the C# property has both get and set accessors, the read & write value should be used.
An abstract property is modeled as a UML property with <<CSharp Property>> stereotype with its abstract stereotype property set to true. For this example, you will model a C# property called distance for the Point structure. This property represents the distance of the point from its origin. Because the distance is calculated from the X and Y coordinates, you will model it as a read-only property. To do this, follow these steps (also see Figure 3):
1. Add a public field named distance to Point, and set its type to int.
2. Apply the <<CSharp Property>> stereotype to the distance field.
3. Set the accessors property of the stereotype to read-only .
Figure 3. C# distance property
Part 4.Modeling indexers
A C# indexer is modeled as a UML operation with <<CSharp Indexer>> stereotype. A UML operation representing an indexer should always be named as this . The formal parameters of the C# indexer become the parameters of the corresponding UML operation and the type of the indexer becomes the return type of the UML operation. Indexer modifiers like new, virtual, extern etc. are available as stereotype properties. A sealed indexer is represented by selecting the Leaf property of the corresponding UML operation.<<CSharp Indexer>> has a property named accessors which can take values : read-only, write-only and read & write depending on whether the C# indexer has only get accessor or only set accessor or both get and set accessors respectively. This is very much similar to accessors property of <<CSharp Property>>.
For this example (Figure 4), you will model a read-only indexer (thus it has only a get accessor) in the DrawingSurface class. This indexer will have two parameters of type int, and it will return a Point type. Basically, the purpose of this indexer is to return a point corresponding to a given row and column on the drawing surface. Follow these steps:
1. Add a UML operation named this to the UML DrawingSurface class.
2. Apply the <<CSharp Indexer>> stereotype to the operation that you added in previous step.
3. Add two parameters of type int to the operation, and name them row and column.
4. Set the return type of the operation as Point structure.
Set the property accessors in the stereotype to read-only (see Figure 4).
<< 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] ... 下一页 >>