Focus
Andrey
andr-sar at yandex.ru
Fri Jan 18 16:04:22 PST 2013
>> MyStruct ms;
>> ms.a = 42; //!!!
>> writeln(ms.a);
>
>
> This is by design, not a bug. All code in a module has access
> to all private members in that same module. This obviates the
> need for the C++ "friend" declarations.
Wikipedia states:
«In general, encapsulation is one of the 4 fundamentals of OOP
(object-oriented programming). Encapsulation is to hide the
variables or something inside a class, preventing unauthorized
parties to use.»
So how am I supposed to hide the variable inside the struct or
class? I don't want anything to access it outside struct
definition. And I don't see any point in giving the opportunity
to access it using "friend" invitation. I'm sure "friend"
explodes the basics of OOP encapsulation mechanics.
Struct is an «container» that owns its declarations and use
special word for this: private. Then comes completely another
data structure and can easily manipulate private members of
another. Only imagine the other man from the neighbor house comes
into your house and take your children without asking only
because he lives on the same street.
More information about the Digitalmars-d
mailing list