`restricted` member variables

forkit forkit at gmail.com
Thu Jun 23 03:55:00 UTC 2022


On Thursday, 23 June 2022 at 01:27:23 UTC, Mike Parker wrote:
>
> https://dlang.org/spec/class.html#invariants
>
> A class in its own module can fully maintain its invariants, 
> even when multiple methods modify a variable. Every function 
> call is bookended with the invariant check.
>
> ...

Well, the 'invariant' statement in D, is interesting, but no 
replacement for strong typing.

I'm comfortable in saying, that a generally accepted central 
principle of good design, for a strongly typed abstract object, 
is that it can protect, isolate, limit access to (.. whatever 
terms you wanna use) its internal representation, and thereby 
ensure any actions on it are limited to the actions that **it** 
defines.

An int type, is a simple, but clear example of this principle.

I cannot put "wtf" into an int.

private(this)  .. (or whatever syntax people are comfortable 
with), would ensure I can declare 'my own' strongly typed 
abstract object.

I now longer have to put that type in its own module, just to 
pretend its strongly typed.

My degree was in psychology, not computer science. But surely 
they teach this concept in computer science?

Or is this all new to D users?



More information about the Digitalmars-d mailing list