Re: Constructor Accessibility - protected ctor inside public class with internal parameter



On Aug 27, 10:15 pm, "jehugalea...@xxxxxxxxx" <jehugalea...@xxxxxxxxx>
wrote:
Hello:

I have a public abstract class. The concrete subclasses must pass an
instance of an internal class to the abstract class' ctor.

I like to make the constructors of my abstract classes protected.
However, since it has a parameter that is of an internal type, I am
forced to make it internal also. This is fine since no one outside my
library can see it.

However, I would prefer to restrict this even more, so that only
subclasses can see the ctor.

"protected internal" provides the relationship:
    visible to code within the library OR ANY subclasses.
I want:
    visible to code within the library AND internal subclasses.

I suppose there is no solution. I was hoping someone could give me
some insight, however.

There is no way to do it in C#, even though the CLR does have the
specifier that you want (it's called FamilyAndAssembly, while
"protected internal" is FamilyOrAssembly), so it is possible to do
that by coding the class directly in IL (or ildasm'ing the .dll
generated from .cs, changing the visibility, and recompiling it). Of
course, it's too inconvenient for any normal development.

The only high-level .NET language I am aware of that exposes
FamilyAndAssembly visibility is RemObjects Oxygene - it has both
"assembly or protected" and "assembly and protected" visibility
specifiers.
.



Relevant Pages

  • RE: Overridden methods
    ... >> overriding method then do some common functionality. ... Programs don't use instances of an abstract class, ... subclasses. ... transmitted without the written permission of the copyright owner. ...
    (perl.beginners)
  • Re: Factory method
    ... > factory method in my abstract class that creates subclasses. ... > constructor in my subclasses must be able to call the constructor in my ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Factory method
    ... > factory method in my abstract class that creates subclasses. ... > constructor in my subclasses must be able to call the constructor in my ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Removing inheritance (decorator pattern ?)
    ... Naturally, the decorator pattern ... could end up with as many Strategy classes as subclasses, ...
    (comp.lang.python)
  • Re: Can sub-classes initialize-instance modify base-classes slot *before* bases initiali
    ... the padding to zero, and the subclasses ought to change that. ...    :accessor dim) ... #<CE2 200DEB8F> is a CE2 ...
    (comp.lang.lisp)