protected internal interface

S

Sgt. Sausage

I know it's not possible, but I need a protected internal interface:

protected internal interface ISomeInterface{

// yadda yadda yadda

}

Basically, I need an interface that is completely accessable
from within the assembly (internal), but is not valid outside
the assembly except for derived objects that live outside
the assembly, but deriving from an object internal to the
assembly (protected).

With the existing interface scoping constraints, I can't do
this. I'm not allowed to declare a protected internal interface.

I've got an object that needs to expose one interface
publicly (easy to do), but internally to the assembly
needs to be accessable in a slightly different manner via
a slightly different interface.

Knowing that this can't be done via interfaces, does
anyone have any alternatives?

I can't believe that this is a really oddball request. Does
anyone have an explanation as to why an interface can't
be declared as "protected internal interface" ?
 
R

Richard Blewett [DevelopMentor]

Assembly 1:

public class Class2
{
protected internal interface IFoo
{
}
}


Assembly 2 referencing assembly 1:

class Bar : Class2
{
protected void Quux(Class2.IFoo f)
{
}
}


Is this what you mean? This is supported (the above compiles fine). Or do you mean something else?

Regards

Richard Blewett - DevelopMentor

http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

I know it's not possible, but I need a protected internal interface:

protected internal interface ISomeInterface{

// yadda yadda yadda

}

Basically, I need an interface that is completely accessable
from within the assembly (internal), but is not valid outside
the assembly except for derived objects that live outside
the assembly, but deriving from an object internal to the
assembly (protected).

With the existing interface scoping constraints, I can't do
this. I'm not allowed to declare a protected internal interface.

I've got an object that needs to expose one interface
publicly (easy to do), but internally to the assembly
needs to be accessable in a slightly different manner via
a slightly different interface.

Knowing that this can't be done via interfaces, does
anyone have any alternatives?

I can't believe that this is a really oddball request. Does
anyone have an explanation as to why an interface can't
be declared as "protected internal interface" ?





---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004



[microsoft.public.dotnet.languages.csharp]
 
S

Sgt. Sausage

Richard Blewett said:
Assembly 1:

public class Class2
{
protected internal interface IFoo
{
}
}


Assembly 2 referencing assembly 1:

class Bar : Class2
{
protected void Quux(Class2.IFoo f)
{
}
}


Is this what you mean? This is supported (the above compiles fine). Or do
you mean something else?

Might be -- I'd have to try it out. I didn't know that interfaces
could be defined from *within* a class. I've been defining then
outside the class and implementing them within the classes.

I'll see if it gets me where I want to go.

BTW -- what does it mean to define an interface from
within a class. How is this different (other than possibly
allowing my scope issue to be solved) how is it different
than defining an interface outside the class.

It seems somhow, well ... wrong. The interface might be
implemented by several different classes. Why should it
be defined within one class and not another -- hence my
habit to declare them outside of classes.

Am I crazy?

You've got an example: protected void Quux(Class2.IFoo f)

which makes an (invalid) association in my mind between
Class2 and IFoo -- IFoo might also be implemented by
Class3, Class4 and Class5 -- why should it be tied to
Class2? I'd much rather have:

protected void Quux(IFoo f) without any knowledge of
Class2 -- ain't that the whole point of an interface? That
it *hides* the actual concrete object behind an interface
such that you don't care if it's a Class2 or Class3 or Class4,
just that it implements IFoo?
 
R

Richard Blewett [DevelopMentor]

The concept of having the interafce as part of a class definition is stating that this interface onlt has meaning in terms of this class. As you had a rquirement that classes outside the assembly could only see the interface if they derived from a particular class (Class2?) then it seemed to fit your model.

Regards

Richard Blewett - DevelopMentor

http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>


Richard Blewett said:
Assembly 1:

public class Class2
{
protected internal interface IFoo
{
}
}


Assembly 2 referencing assembly 1:

class Bar : Class2
{
protected void Quux(Class2.IFoo f)
{
}
}


Is this what you mean? This is supported (the above compiles fine). Or do
you mean something else?

Might be -- I'd have to try it out. I didn't know that interfaces
could be defined from *within* a class. I've been defining then
outside the class and implementing them within the classes.

I'll see if it gets me where I want to go.

BTW -- what does it mean to define an interface from
within a class. How is this different (other than possibly
allowing my scope issue to be solved) how is it different
than defining an interface outside the class.

It seems somhow, well ... wrong. The interface might be
implemented by several different classes. Why should it
be defined within one class and not another -- hence my
habit to declare them outside of classes.

Am I crazy?

You've got an example: protected void Quux(Class2.IFoo f)

which makes an (invalid) association in my mind between
Class2 and IFoo -- IFoo might also be implemented by
Class3, Class4 and Class5 -- why should it be tied to
Class2? I'd much rather have:

protected void Quux(IFoo f) without any knowledge of
Class2 -- ain't that the whole point of an interface? That
it *hides* the actual concrete object behind an interface
such that you don't care if it's a Class2 or Class3 or Class4,
just that it implements IFoo?








---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004



[microsoft.public.dotnet.languages.csharp]
 
S

Sgt. Sausage

Richard Blewett said:
The concept of having the interafce as part of a class definition is
stating that this interface onlt has meaning in terms of this class. As you
had a rquirement that classes outside the assembly could only see the
interface if they derived from a particular class (Class2?) then it seemed
to fit your model.

I'm sorry -- maybe I didn't state it clearly.

What I said was:
Basically, I need an interface that is completely accessable
from within the assembly (internal), but is not valid outside
the assembly except for derived objects that live outside
the assembly, but deriving from an object internal to the
assembly (protected).

Which made perfect sense to me, but after re-reading
is a bit vague.

I need the interface to be implementable (?) by any
old object in the assembly -- but only accesseble
outside the assembly from objects that inherit from
within the assembly.

I *need*

Assembly1:

protected internal interface ISomeRandomInterface
{
// yadda yadda yadda
}

public Class1: ISomeRandomInterface
{
// yadda yadda yadda
}

public Class2: ISomeRandomInterface
{
// yadda yadda yadda
}

public Class3: ISomeRandomInterface
{
// yadda yadda yadda
}

Assembly2:

public Class11: Class1
{
//Has access to ISomeRandomInterface
// it inherits from Class1
}

public Class22: Class2
{
//Has access to ISomeRandomInterface
// it inherits from Class1
}

public Class99
{
// can't do anything with ISomeRandomInterface
// it's internal to Assembly1 and this guy doesn't
// inherit from Assembly1
}

// nobody else has access because they're not
// in Assembly1 and they don't inherit from
// objects in Assembly1 that implement
// ISomeRandomInterface.


It would be nice, but c# specifically does *not* allow
my:

protected internal interface ISomeRandomInterface
{
// yadda yadda yadda
}

I'm stuck and looking for help. Your attempt at help
is appreciated , but it doesn't get me where I'm wanting
to go.

Thanks anyway!
 
J

Jon Skeet [C# MVP]

I need the interface to be implementable (?) by any
old object in the assembly -- but only accesseble
outside the assembly from objects that inherit from
within the assembly.

I *need*

<snip>

What's the downside of just making it a public interface and letting
any class implement it?
 
G

Guest

protected is only meaningful if it's used on members of a class.

to do what you want, you should use an abstract base class with all the
appropriate members declared as internal protected.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top