Re: Encapsulation



Arne Vajhøj wrote:
Jon Harrop wrote:
Arne Vajhøj wrote:
Jon Harrop wrote:
I have two separate classes and would like the members of one class to
have access to the private members of another class. What is the
idiomatic C# solution to this?

I believe C++ would use "friends".
The typical C# solution would be to put the classes in same
assembly and use "internal" accessibility.

That only restricts accessibility to the million lines of other code that
happens to be in the same assembly, which is such a weak constraint as to
be of no practical use.

I don't think millions of lines of C# code in one assembly
is good at all.

Whether I have one line or a million lines, the idea of restricting
accessibility to a single-level (the assembly) does not scale. Moreover, if
I reduce the size of my assemblies then I increase the probability
that "internal" cannot work because access is required from another
assembly.

--
Dr Jon D Harrop, Flying Frog Consultancy
http://www.ffconsultancy.com/products/?u
.



Relevant Pages

  • Re: Encapsulation
    ... have access to the private members of another class. ... I believe C++ would use "friends". ... assembly and use "internal" accessibility. ... But it means that the source code and the assemblies are not ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: override method without extending visibility
    ... Is Handlespace in the same assembly as IHandlespace? ... accessibility of the method. ... Two different assemblies, ... InternalsVisibleToAttribute in play. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Private member access.
    ... I'm not quite seeing how the reflection issue arises if type-specific ... > FieldInfo.SetValueworks perfectly well on private members. ... > assembly access to private members. ... > assemblies that I have control over - so they can be modified if ...
    (microsoft.public.dotnet.security)
  • Private member access.
    ... FieldInfo.SetValueworks perfectly well on private members. ... assembly access to private members. ... assemblies that I have control over - so they can be modified if ... required to grant access (making the members public is a very last ...
    (microsoft.public.dotnet.security)

Loading