Skip to main content

Element: Class

A class is a logical unit with encapsulated data and operations. It also represents a variable type that can be instantiated. When the instance of a class is assigned as a variable to another class, this is referred to as the role or expression of the class.

A class can provide a method FB_Init which is called when initializing an instance.

A class can inherit from another class. This relationship is called a generalization.

A class can instantiate another class. This relationship is called a composition.

A class can recognize another class. This relationship is called an association.

A class can be a POU, a library POU (type: program), a function block, or a function.

_uml_img_class_all.png

(1)

Command icons

Tip

When a class is selected, its command symbols are visible.

(2)

Header

  • ID for the POU type

    • <<program>> for a program (PRG)

    • No ID for a function block (FB)

    • <<function>> for a function (FUN)

    • <<library>> for a library POU

    • <<missing>> for a library POU whose library is not integrated in the project

    • <<compiled>>: For a library POU from a compiled library

      Note

      Not all information may be available.

  • Name of the POU

(3)

List of attributes

The entry has the following format: <attribute name> : <attribute type> <label>

Example: fbBase : FB_BaseClass

ID: <label>

  • {input}: For a variable of VAR_IN scope

  • {output}: For a variable of VAR_OUT scope

  • None: ID for an internal, invisible variable (type: VAR)

(4)

List of operations (actions, methods, or properties)

Example:

ACT_DoIt(){action}

METH_DoIt(...) DWORD

PROP_Counter Set(...)

PROP_Counter Get (...)

An entry for methods has the format:

+ <method name> (<variable name> : < variable type> ) <return type>

In the case of an entry for an _cds_icon_interface_property.png interface property, the special Set and Get methods are listed.

An entry for actions has the format:

<action name> () {action}

The following applies for <label>:

  • Only one action is identified with the {action} ID.

  • A method or an interface property _cds_icon_interface_property.png (special method) do not have an ID.

Properties

Identifier

Name of the class

Example: Manager_A

User input

The class has expanded attribute and operation lists that are identified with _uml_icon_checkbox_minus.png. Command icons are visible above the class. You can use these to insert relationship elements.

Action

Result

In the BaseClass class, click the _uml_icon_delete_shallow.png command icon.

The BaseClass class is deleted from the class diagram only. The object itself remains in the project.

Tip

After being deleted, the class is displayed in the ToolBox view in Incoming cross references or Outgoing cross references. The requirement for this is that you select an element in the class diagram that has a relationship to the deleted class.

Click the _uml_icon_delete_deep.png command icon.

The BaseClass class is deleted in the class diagram only. The object is removed and does not exist anymore.

  1. Click the _uml_icon_composition.png command icon.

  2. Click a blank area in the diagram.

    The Add POU dialog opens.

  3. Specify a name for the new object.

    NewClass

  4. Click the Add button to end the dialog.

The NewClass function block is generated and an instance of the first class is instantiated there.

A composition arrow points from the new NewClass class to the first BaseClass class.

The class has been extended by the declaration of a function block instance of the first class.

FUNCTION_BLOCK NewClass
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
    InstanceBase : BaseClass;
END_VAR
  1. Click the _uml_icon_composition.png command icon.

  2. Click an the second class.

A composition arrow points from the second class to the first class.

The second class has been extended by the declaration of a function block instance of the first class.

FUNCTION_BLOCK SecondClass
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
    InstanceBase : BaseClass;
END_VAR
  1. Click the _uml_icon_association.png command icon.

  2. Click a blank area in the diagram.

    The Add POU dialog opens.

  3. Specify a name for the new object.

    NewClass

  4. Click the Add button to end the dialog.

The new NewClass class is generated and a pointer of the first class is declared there.

An association arrow points from the new class to the first class. The first BaseClass class recognizes the new NewClass class.

The NewClass class has been extended by the declaration of a pointer to the BaseClass class.

FUNCTION_BLOCK NewClass
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
    ptrBase : POINTER TO BaseClass;
END_VAR
  1. Click the _uml_icon_association.png command icon.

  2. Click the existing, second class.

An association arrow points from the first class to the second class. The first class recognizes the second class.

The first class has been extended by the declaration of a pointer to the second class.

FUNCTION_BLOCK SecondClass
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
    ptrBase : POINTER TO BaseClass;
END_VAR
  1. Click the _uml_icon_generalization.png command icon.

  2. Click a blank area in the diagram.

    The Add POU dialog opens.

  3. Specify a name for the new object.

    NewClass

  4. Click the Add button to end the dialog.

A new class is generated which inherits from the first class.

A generalization points from the new class to the first class. The new class inherits from the first class.

The declaration of the new class has been generated with EXTENDS as an extension of the first class.

FUNCTION_BLOCK ClassNew EXTENDS BaseClass
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
END_VAR
  1. Click the _uml_icon_association.png command icon.

  2. Click the existing, second class.

A generalization points from the first class to the first class.

The declaration of the second class has been generated with the extension of the first class.

FUNCTION_BLOCK SecondClass EXTENDS BaseClass

  1. Click the _uml_icon_realization.png command icon.

  2. Click a blank area in the diagram.

    The Add Interface dialog opens.

  3. Specify a name for the new object.

    ITF_New

  4. Click the Add button to end the dialog.

An interface is generated which is implemented from the outgoing class.

An implementation arrow points from the class to the new ITF_A interface.

Now the class implements the new interface. The declaration of the class has been extended with the implementation.

FUNCTION_BLOCK BaseClass IMPLEMENTS ITF_New
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
END_VAR
  1. Click the _uml_icon_association.png command icon.

  2. Click an existing interface.

The interface is implemented by the class.

A realization arrow points from the class to the interface.

The declaration of the class has been extended with the implementation of the interface.

FUNCTION_BLOCK BaseClass IMPLEMENTS ITF_A
VAR_INPUT
END_VAR
VAR_OUTPUT
END_VAR
VAR
END_VAR
  1. Click the class name.

    The name is outlined in blue after the first click.

  2. Click it a second time.

    After you click the second time, an input field opens for changing the name.

  3. Change the class name.

The object name (in the device tree or in the POUs view) has been automatically adapted in the declaration.

  1. Click an attribute name or operation name.

    The name is outlined in blue after the first click.

  2. Click it a second time.

    After you click the second time, an input field opens for changing the name.

  3. Change the name.

The change is applied in the project synchronously and automatically.

Double-click the class element.

The corresponding object editor opens.

Examples

Example 6. Composition: Fb_D contains Fb_A
_uml_img_example_composition.png
FUNCTION_BLOCK Fb_D
VAR
    VarFb_A: Fb_A;
    ...
END_VAR


Example 7. Association: Fb_A recognizes Class_2
_uml_img_example_assoziation_class_simple.png
FUNCTION_BLOCK Fb_A
VAR
    Class_2 : POINTER TO Class_2;
END_VAR


Example 8. Generalization: Fb_A inherits from Fb_Base
_uml_img_example_generalization_function_block.png
FUNCTION_BLOCK Fb_A EXTENDS Fb_Base


Example 9. Implementation: Class_A implements Itf_A
_uml_img_example_realization.png
FUNCTION_BLOCK Class_A IMPLEMENTS Itf_A