Sealed classes - would you want them in D?

Mike Parker aldacron at gmail.com
Tue May 15 04:22:30 UTC 2018


On Tuesday, 15 May 2018 at 02:32:05 UTC, KingJoffrey wrote:

>
> - Object independence
> - Do not violate encapsulation
> - Respect the interface

This is what I don't get from your position. What is 
encapsulation? Here's what Wikipedia says [1]:

"Encapsulation is used to hide the values or state of a 
structured data object inside a class, preventing unauthorized 
parties' direct access to them. Publicly accessible methods are 
generally provided in the class (so-called getters and setters) 
to access the values, and other client classes call these methods 
to retrieve and modify the values within the object."

This has been my understanding of encapsulation since I first 
learned of it years ago. How is this broken in D? Only if you 
insist on viewing it in a strictly theoretical sense. As a matter 
of practical reality, it is not broken.

If you have access to the internals of the class, you also have 
access to the rest of the module. No client of the class outside 
of the module has any access to the implementation. I showed you 
an example earlier of how silly it would be to force the rest of 
the module to use some sort of "module private" interface.

The class in D *is* encapsulated. The interface *is* respected. 
I'm not sure what you mean by object independence.


[1] 
https://en.wikipedia.org/wiki/Encapsulation_(computer_programming)


More information about the Digitalmars-d mailing list