June 20, 2019

Object orientation for C programmers


Creating a normal program can be done with C like languages. The user defines some functions which have input parameters and in the main loop the functions are called in a sequence. The surprising information is, that object oriented programming is the same but it is more powerful. The first thing which has to be introduced are so called structs. A struct is C variable which contains more than a single item. A struct is for example a pixel which can have an x value and also an y value at the same time.
In the classical C programming context, variables and structs are defined at a certain position in the program code. Usually inside the function. In the object oriented paradigm, global variables are used. That means, the struct defintion doesn't belongs to a certain function but is defined globally on top of the program. All functions have access to the struct. And now comes the best part, if the struct keyword is replaced by the class keyword in C++ we have written the first true object oriented program.
What i want to explain is, that the transition from classical structured programming in C to modern object oriented programming in C++ is a continuous process.
1. normal c program
2. structs
3. global structs
4. object oriented classes
If somebody doesn't have understood object oriented programming at all, he can simply take a step backward. Instead of using the class keyword, he can stay in the struct paradigm. That means, he is not defining classes and doesn't inherit from super classes, but he only aggregates variables to a table. Object orientated programming was never planned as a revolution in software engineering but it's a small improvement over normal structured programming.

No comments:

Post a Comment