Why do private member variables behaved like protected in the same module when creating deriving class?

unprotected-entity unprotected-entity at gmail.com
Thu Nov 1 02:44:47 UTC 2018


On Wednesday, 31 October 2018 at 20:46:05 UTC, Zot wrote:
> On Monday, 29 October 2018 at 09:25:07 UTC, unprotected-entity 
> wrote:
>> Just how often does one need to access the private members of 
>> a class, within a module?
>
> a lot actually. e.g. unittests

that does not compute.

all you are doing is further coupling unit-tests, with all the 
other crap that is already coupled in your module.

Too many programmers these days, have no concept of clean 
architecture.

You should be find ways to further decouple your code, not 
finding even more ways to further couple it.

Since, in D, there is no concept of encapsulation, or information 
hiding, *within* a module, it (sadly) promotes the wrong type of 
architecture, by default. The module is just a convenient hack to 
avoid thinking about decoupling. Everything could dependent on 
everything else in your module - you have to read the whole 
10,000 lines to discover what it's all about..(that's how much of 
phobos is designed, it seems).

It's C like programming, masquerading as modern software design.

if you want to test something that is private, call its public 
interface. that seems a pretty sensible guideline to me.

and why is it so hard to put the unit test inside the actual 
class?

that too seems like a pretty sensible guidline, to me.

many on this forum have said, that the amount of code in your 
module should be fairly minimal (especially if you take the one 
class per module concept seriously).
of course, in practice, that is not what happens - just look at 
phobos.

the module should be a grouping of related functionality. that 
doesn't mean it should have no concept of encapsulation of 
information hiding within it - that will only lead to bad design.

---------------
module test;

class Test
{
     private int Value;

     unittest
     {
         Test t = new Test();
         assert(t.Value == 10);
     }

}
----------------



More information about the Digitalmars-d mailing list