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 and abstract commonalities of different classes in an abstract basic class. Implement specific aspects in non-abstract subclasses.
This principle mimics how an interface is used. Interfaces correspond to purely abstract classes that only contain abstract methods and properties. Conversely, 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_BaseThe 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 : UINTMETHOD ABSTRACT Executewhereas 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_BaseNon-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