When working with OOP concepts as discussed in the series “The three pillars of OOP” it might get hard to keep track of your program architecture when your program grows. As this is a common struggle in the world of the programming some smart people came up with the Unified Modeling Language. Or short UML. With UML we can visualize and develop our software graphically.
It’s little known (and used as far is I’m aware) but TwinCAT does support designing and developing with UML. Which is unfortunate because it’s can give great insights in your architecture. So, in this short post I’ll show how to create an UML class diagram together with an example diagram of the code I used for “The three pillars of OOP”. Note, this blog not meant for the explanation of UML diagrams. There are far better resources for that available.
Add a class diagram in TwinCAT
To add a class diagram to TwinCAT press the right mouse button on your POU’s and select ADD > Class diagram. In the ‘add class diagram dialog’ you can select if you would like to import your current code into the class diagram.
From the toolbox you can now drag and drop different UML components to the designer. Notice that any change you make in the class diagram is automatically updated in your ‘real’ source code. You can also rename displayed element names directly in the UML diagram.
Example UML diagram in TwinCAT
The following UML diagram is generated from code I used for the blogs in the serie “The three pillars of OOP“. It gives a good and fast overview about the relations between the different used objects. Note that even though this diagram is automatically generated it did need some manual fine tuning for the layout.
An UML diagram gives a good overview of you systems architecture. Also in TwinCAT an UML diagram is easily generated and gives the user the ability to graphically design a system architecture. Personally I find the graphical handling in TwinCAT not very user friendly for designing and developing. But as overview of your system it can be useful.