Modeling C# overloaded operators

You can model C# overloaded operators as UML operations.

Before you begin

Before you perform this procedure, a UML model must be open with the C# transformation profile applied.

About this task

To model overloaded operators:

Procedure

  1. Add a new operation to a class and name it as the desired operator. For example, name the operation operator !=.
  2. Define the operator using the following steps:
    1. Set the visibility of the operation to Public.
    2. Set the qualifiers of the operation to Static.
    3. Set the return type of the newly created operation to <Primitive Type> Boolean.
    4. Add two parameters of the type containing class to the newly created operation. For example, name the parameters c1 and c2.

Example

For example, you can overload the following two operators in the context of a class, C1:

   Equal (==) 
   Not equal (!=)
Figure 1. Class C1 in the diagram.
Class C1 with overloaded operators modeled as UML operations != and ==.
Figure 2. Properties set for UML operation operator !=.

Feedback