3 ms·
Object oriented programming is quite simple in theory. Say you want to draw a window, it's one of many windows in your program. You could either write out the
by Dalewyn 4y ago
Object oriented programming is quite simple in theory.
Say you want to draw a window, it's one of many windows in your program. You could either write out the code to draw a window each and every time you want to draw a window, but that's probably inefficient at best and a nightmare to maintain at worst.
So you instead write a generalized class to draw a window. You then invoke that class as a new object when you want to draw a window, and pass to it any information unique to this particular window (eg: dimensions, contents).
This means the code to draw a window only exists once in your program. If you need to change how windows are drawn, you only need to change the one class instead of thousands of instances of drawing windows.
In essence, any action that you are likely to repeat many times in a program benefits from object oriented programming because it centralizes the code in one place and is abstracted away when the time comes to use it.
By contrast, if a given action is something a program would only do once or at most very seldomly, object oriented programming starts to lose importance because there's little value in centralizing and abstracting away a piece of code that will only ever execute once anyway.
- civilized 4y ago> In essence, any action that you are likely to repeat many times in a program benefits from object oriented programming because it centralizes the code in one place and is abstracted away when the time comes to use it. This isn't really the unique benefit of OOP. Plain functions also centralize code in one place and allow you to avoid writing repetitive code.
- bluefirebrand 4y ago> So you instead write a generalized class to draw a window Using Classes when you should be using functions is one of my biggest peeves with OOP and the programmers who write it. Especially those who wind up writing a "Window" Class with one function "draw" and nothing else
- kaba0 4y agoTo make it more OOPy you would probably give a few instance variables to the window like width, height, title, etc. That way, a simple drawWindow function would not be a better replacement anymore.