Accessibility modifier question

  • Thread starter Thread starter Hans De Schrijver
  • Start date Start date
H

Hans De Schrijver

I'm a little confused about an accessibility issue I'm encountering. Maybe
someone can shed some light on it for me.

I have an abstract class AClass1, an abstract class AClass2 that inherits
from AClass1, a regular class 'Class3' that inherits from AClass2 and a
regular class Class4 that inherits from AClass1.
Summarized:
AClass1 -> AClass2 -> Class3
AClass1 ->Class4

Any class that derives from either AClass1 or AClass2 must provide a static
method GetPath(), the implementation of which is only known to the derived
class (Class3 and Class4).
Given this requirement, I thought I should create an abstract GetPath()
method in AClass1, and override it in the derived class Class3 and Class4.
In AClass1 I declared GetPath() as protected abstract, so that only derived
Class3 and Class4 can access it.
However, in Class3 I cannot create GetPath() as public static override
(compiler error), only protected override. However, protected override means
I cannot access the function from outside as Class3.GetPath(), in fact I
cannot access it at all.

I'm probably not understanding a basic concept here... I sure would
appreciate some help.

Thanks in advance!

-- Hans De Schrijver
 
Hans De Schrijver said:
I'm a little confused about an accessibility issue I'm encountering. Maybe
someone can shed some light on it for me.

I have an abstract class AClass1, an abstract class AClass2 that inherits
from AClass1, a regular class 'Class3' that inherits from AClass2 and a
regular class Class4 that inherits from AClass1.
Summarized:
AClass1 -> AClass2 -> Class3
AClass1 ->Class4

Any class that derives from either AClass1 or AClass2 must provide a static
method GetPath(), the implementation of which is only known to the derived
class (Class3 and Class4).

That's your problem to start with - static methods aren't really
inherited (and aren't polymorphic) so there's no such concept of a
static abstract method, which is what it sounds like you want.
 
Hans,

There is no abstract static concept here.
You might try using reflection to simulate it.
 
Back
Top