3 ms·
if i were writing an intro to programming book, i would introduce OO as a means of building encapsulation. i'd only get into inheritance in later chapters.
by parpfish 3y ago
if i were writing an intro to programming book, i would introduce OO as a means of building encapsulation. i'd only get into inheritance in later chapters.
- gentleman11 3y agoYou can have encapsulation without oop. Polymorphism is the real benefit of oop imho
- gorjusborg 3y ago> Polymorphism is the real benefit of oop imho It's pretty much the definition of OOP. The core feature of OOP is just bundling functions with the state it processes. When you bundle state and functions together, you can't predict what calling the function will do without knowing both the code and state. You can say its 'the real benefit', I guess, but that feels like circular reasoning. Its pretty much the definition of what OOP is, so calling it a benefit feels weird. Unfortunately, designing systems as a collection of distributed state machines tends to become maintenance nightmare. Functions and data being separated tends to make code better, even when working in so-called 'OOP' languages.
- jcelerier 3y ago> You can say its 'the real benefit', I guess, but that feels like circular reasoning. Its pretty much the definition of what OOP is, so calling it a benefit feels weird. It's a benefit compared to how people were writing code before it became mainstream (for polymorphism: by jumping to data-defined parts of the code and hoping for the best, and for encapsulation: subroutines working on global variables).
- tubthumper8 3y agoWhich kind of polymorphism? Subtype polymorphism I'm guessing?