News for hackers. Stuff that matters.
Re:Inheritance versus Composition by kingdomcome50 on Thursday May 09, 2019 @11:31AM (#19869147)
Of course you gain something. By encapsulating all methods that operate on X and Y in a single place, Point (where X and Y are defined), it is now _much_ easier to change X and Y. It's all right there in one file.

Point {x, y} may not be the best example, but you can certainly see how this can be beneficial should X or Y become something even slightly more complex. And this is the purpose of encapsulation - to make a system easier to understand and therefore easier to change.

There are no comments on this comment yet.