3 ms·
You could generalize the described approach even further and have a single global function called 'message', so that your entire app consists entirely of statem
by vannevar 11y ago
You could generalize the described approach even further and have a single global function called 'message', so that your entire app consists entirely of statements like:
message(receiver, msg)
Sure, it's encapsulated, but it's hardly modular. The author knew not to do this because he's undoubtedly already had a lot of experience with OOP. So writing OOP-like functions comes easy to him. I'm not sure that would be the case for a beginner, who could also go to the other extreme and have a different function for everything, even if two methods differ only in their arguments:
add_one_to(number)
add two_to(number)
etc.
The point of OOP is that it provides some guidance in navigating between the two extremes, and tools to manage modularity and redundancy (like inheritance and composition). Encapsulation isn't the sole benefit.