typeof on protected field
DigitalDesigns
DigitalDesigns at gmail.com
Sun Jun 17 22:21:54 UTC 2018
On Sunday, 17 June 2018 at 02:29:12 UTC, Adam D. Ruppe wrote:
> On Saturday, 16 June 2018 at 08:32:38 UTC, DigitalDesigns wrote:
>> I need to get the protected and private members for
>> serialization.
>
> This breaks encapsulation.
>
> A better design would be to have a class know how to serialize
> itself via a serializable interface.
Yeah, but that is a lot of extra work when it is generally
unnecessary and breaks encapsulation far more than a CT
reflection based scheme. CT reflection should not have these same
restrictions and encapsulation does not technically apply.
Encapsulation cannot reflect in a generic way. Reflection can be
generic and hence handle any case. OOP and Reflection are two
different things and encapsulation is mainly for OOP. After all,
encapsulation is optional and one can code so things are highly
dependent... so why should reflection break in one case but not
the other? One can easily deal with encapsulation in reflection
if they desire but it shouldn't be forced as it take away many
useful possibilities.
With proper CT reflection one does not have to touch any code and
it can just work. With oop one has to modify the classes to
support serialization. That's a huge difference.
More information about the Digitalmars-d-learn
mailing list