You are on page 1of 20

Object-Oriented-Programming

CoDeSys 3.5
Andrew Aung
12-May-2023
Object Oriented Programming
Different between Procedural programming and OOP

• Object oriented looks at the world and how the single components
(objects) act with each other. The data plus the methods and
properties are bundled up and encapsulated. The program is built
from bottom up based on the objects.

• Procedural programming segments the task into subfunctions over


functional decomposition. This is based on a top-down method where
steps in the program are done in sequence. The handling of variables
and data structures are done over functions.

2 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Object Oriented Programming
Terms

• Terms used when talking about OOP are


✓ Interface
✓ Class
✓ Method
✓ Property
✓ Object
✓ Inheritance
✓ Polymorphing

3 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Object Oriented Programming
Interface

• An interface describes how an object


will act with the around environment

• The interface consists out of methods and


properties
• There is no program code inside the
interface

4 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Object Oriented Programming
Interface

Here an inheritance from an interface can be


done through Extends

5 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Object Oriented Programming
Class

• As class describes a group from which


an object can come from

• A class can inherite from another class


• A class can implement an interfaces
• In the class the program code is written

6 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Object Oriented Programming
Class

• To make a class you use the function


block POU

Inheritance from another class

Allocation of the interface of the class

Access type of the class


Final
Public
Private
7 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business
Object Oriented Programming
Method

• A method is an enclosed code for an


explicit functionality

• Methods are part of a class


• A method can have variables need ed to
be handed over

8 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Object Oriented Programming
Method

9 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Object Oriented Programming
Method

• A method can have the access types


✓ Public
✓ Private
✓ Internal
✓ Final

10 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Object Oriented Programming
Property

• A Property is a special method that


lets you interact with the

• A property consist out of two special


methods
• The set method allows you to write to the
property
• The get method allows you to read from
the property

11 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Object Oriented Programming
Property

12 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Object Oriented Programming
Property

• A property can have the access types


✓ Public
✓ Private
✓ Internal
✓ Final

13 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Object Oriented Programming
Object

• An object is the instanciation of a


class

• Works the same as a function block


when declaring

14 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Object Oriented Programming
Inheritance
• Inheritance is defined through using the
word EXTENDS
• Through inheritance a class can use all
methods and properties of the previous
class
• The inheriting class can override a method
• To access the method of the parent class
the super pointer can be used
SUPER^.<method>
• To access local methods THIS^.<method>
is used
15 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business
Object Oriented Programming
Polymorphing

• Polymorphing is using the same


interface in different types of objects

Conveyor

Press

Loader

16 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Variables
Var_Config

• The variables definition type VAR_CONFIG allows you map


physical IO to function blocks, classes as also program
• They can be used as placeholder to define the direct address
later
• The Physical addresses are all located in the same area
• A program can be written without having the specific IO
address available

17 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Variables
Var_Config

• In the declaration of the POU the


placeholder is allocated with the
AT %I* or AT %Q*
syntax

18 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business


Variables
Var_Config
• A global variable list has to be
VAR_CONFIG
generated with the declaration space
END_VAR

Inside this space the exact declaration


tree of the explicit variable has to be
named followed by the address

19 | ACCELERATE DANFOSS INDUSTRIAL DIGITALIZATION – DAW#10 Classified as Business

You might also like