loading...

re: Composition over encapsulation VIEW POST

FULL DISCUSSION
 

Define encapsulation

  1. the action of enclosing something in or as if in a capsule.
  2. the provision of an interface for a piece of software or hardware to allow or simplify access for the user.

If we take "1" then inheritance breaks the encapsulation, because other class knows some details for parent class.

If we take "2" then composition doesn't break it - you can provide interfaces and use composition.

 

Am i correct to make the conclusion that #2 supports the idea that Kasey Speakman introduced in his response about DTOs?

Thanks for this response! I think this is turning into a real ”aha moment”! πŸ‘πŸ‘

 

Maybe to some extent.

The main question is what you try to isolate from what? There are different ways to build isolations, in some PL you can restrict access to inside of the module, ot you can use closures to hide some data, or something like wrapper object which takes callback-functions (like monad).

I'm not sure I fully understand your initial question.

Code of Conduct Report abuse