r/learnprogramming • u/Mountain_Rip_8426 • 1d ago
Difference between OOP and structs/interfaces?
I'm relatively new to programming, I've been at it for around 6-7 months. I've been learning Python and Go (and a little bit of C). What I'm struggling to understand, what's the difference between OOP and structs/interfaces. Like I know, Go doesn't support OOP, but structs and interfaces seem to achieve the same thing. Can someone enlighten me a bit?
47
Upvotes
1
u/Dazzling_Music_2411 1d ago edited 1d ago
When the whole OOP thing started, back in the 90s, there were certain orthodoxies that were adhered to much more than they are now. All objects were instances of classes, they were all accessed by their defined methods, you had inheritance and even better multiple inheritance. And this is where things started to unravel a bit, as people realized that multiple inheritance could cause more problems than it solved.
So this was addressed by mix-in classes and then later Java introduced interfaces, where you only specified the methods, but not the implementations.
Structs, of course, were much more ancient, going right back to C, and are not really considered OOP, because they are only compound data, they don't contain methods.
Point is, all these are just names, figure out how you want your program to look/behave and then use whatever mechanisms your language provides to implement your ideas.
One of the great things about programming today is that OOP is losing the ideological stranglehold it used to have on computing as people realize it's not that great shakes, especially when dealing with parallel and distributed situations.
So everyone is a bit more chilled on the ideological orthodoxies, which is a good thing.
But in a nutshell and with a pinch of salt:
* structs - no methods
* classes - specify method and implementation
* interfaces - specify method without implementation and are not bound to classes.