Abstract Factories: Introduction
Table of Contents
Abstract Factories
A factory is used to create concrete objects without the application knowing the concrete class behind the object because it works with a base or an interface. This achieves a decoupling between the user of an object and the concrete class. With an abstract factory, the application does not use a concrete factory but, as the name suggests, an abstract base factory or factory interface. There is again an example to understand it better.
Abstract factories in TwinCAT 3 not only require a method to create an object, but also a method to destroy the object. This is because the operator __DELETE always requires the pointer to the concrete class. Except the new class provides a method for self-destruction it is possible with __DELETE(THIS);
.
The Example
An annoying and typical problem in automation technology is error management. The other areas in computer science do not know this problem in this form. In the example, there will be alarm reporting classes, which one simply creates as a programmer. The classes are separated from the view layer. It is a little more source code necessary, but it is worth it. If you do not need context, you can just look at the factories chapter.