ABSTRACT concept
The keyword ABSTRACT is available for function blocks, methods and properties. It enables the implementation of a PLC project with abstraction levels.
Abstraction is a key concept of object-oriented programming. Different abstraction levels contain general or specific implementation aspects.
Available from TC3.1 Build 4024 |
Application of the abstraction
It is useful to implement basic functions or commonalities of different classes in an abstract basic class. You implement specific aspects in non-abstract sub-classes.
The principle is similar to the use of an interface. Interfaces correspond to purely abstract classes that contain only abstract methods and properties. An abstract class can also contain non-abstract methods and properties.
Rules for the use of the keyword ABSTRACT
- Abstract function blocks cannot be instanced.
- Abstract function blocks can contain abstract and non-abstract methods and properties.
- Abstract methods or properties contain no implementation (only the declaration).
- If a function block contains an abstract method or property, it must itself be abstract.
- Abstract function blocks must be extended in order to be able to implement the abstract methods or properties.
- Hence: A derived FB must implement the methods/properties of its basic FB or it must also be defined as abstract.
Sample
Abstract basic class:
FUNCTION_BLOCK ABSTRACT FB_System_Base
The commonalities of all system modules are implemented in this abstract basic class. It contains the non-abstract property "nSystemID" and the abstract method "Execute" for this:
PROPERTY nSystemID : UINT
METHOD ABSTRACT Execute
whereas the implementation of "nSystemID" is the same for all systems, the implementation of the method "Execute" differs for the individual systems.
Non-abstract sub-class:
FUNCTION_BLOCK FB_StackSystem EXTENDS FB_System_Base
Non-abstract classes that are derived from the basic class are implemented for the specific systems. This subclass represents a stack. Since it is not abstract, it must implement the method "Execute" that defines the specific stack execution:
METHOD Execute