So I looked through many related questions and none of them seem to fit all the way. At least not in my current understanding. As this is a simple issue, I'm going to be concise with my question and code.
I have five classes:
internal class A
internal abstract class B : A
internal abstract class C : B
public class D : C
public class E {
public void X(C c) { }
}
There is an obvious accessibility issue here with the parameter C
being used in a public
method. I need to access class D
without exposing class C
. I believe this may be due to the nature of the abstract
keyword, and my minimal experience with using it.
To date I have never had a known need to create an abstract
class, and this is my first time dealing with it on this level. From my understanding, it isn't really necessary in this case to use abstract
classes so long as I remember to implement everything properly.
My Questions
- Should I create a class
F
that has a private instance ofD
as a sort of wrapper to prevent exposure? - What is a solid reason to use
abstract
as I don't believe this code is a good example of it. - What are other ways I can expose
D
without exposingA
,B
, orC
?
Notes
- I am trying to be surgical with my current changes.
- Originally all classes were private.
I've looked at many related posts (here are a few of them):