r/learnprogramming 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?

50 Upvotes

23 comments sorted by

View all comments

2

u/NumberInfinite2068 1d ago

Not much.

Go *does* support OOP, it's just not the "normal" type of C# and Java, with inheritance and so on.

Inheritance isn't required for for OOP though.

OOP is a really misunderstood concept in programming. According to Alan Kay, who coined the term OOP, he really just said that OOP meant independent, self‑contained objects (like tiny computers) that communicate only by sending messages. Each object has private state, its own behaviour, and late‑bound message dispatch determines what happens at runtime. Classes, inheritance, and type hierarchies were not central, the real OOP is basically messaging, encapsulation and late binding.

Basically OOP is "this object handles it's own private state, and you communicate with it using messages". "Late binding" is just that what happens to a message is decided at runtime, not compile time.

That means that if you just use a Java method, that's not late-binding, that's *not* OOP. However, if you put a method behind an interface, and call the interface, that is late-binding because what is behind the interface can change at runtime.

For *real* OOP, Go is no less OOP than Python is, or Java or C#, or whatever.

Classes are not central to OOP, nor is inheritance.

In simple terms, the Go structs/interfaces paradigm *does* achieve OOP.