Inheritance

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to make a base class such that it can only be inheritted by derived
classes that exist in the same project as the base class. But I want the
classes (at least the derived classes) to be public. Can this be done?
 
Try marking the base class with the FRIEND identifier (VB.NET). This gives
the class assembly level scope. Then mark the derived classes as Public.
 
I want to make a base class such that it can only be inheritted by derived
classes that exist in the same project as the base class. But I want the
classes (at least the derived classes) to be public. Can this be done?

Sure, just don't expose any public constructors from the base class
(make them internal).



Mattias
 
Humm... doesn't this fail because "the derived class expands the access of
the base class"? Did you do something else to overcome this?
 
While I understand your solution it doesn't quite solve my problem - probably
because I didn't describe my problem properly in the first place. In your
solution the base class is still public - even though you can't create any
objects from it - which means I still get a 'cannot expose a Friend type
outside of the Public class' exception when I do this...

Friend Class X
...
End Class

Public MustInherit Class Y
Protected m_X1 as X
End Class

So, now that I've (hopefully) explainied myself better, can I do this. I
don't want class X to be public but I want m_X1 to be accessable to classes
that inherit from Y. Can this be done?
 
Dick said:
While I understand your solution it doesn't quite solve my problem - probably
because I didn't describe my problem properly in the first place. In your
solution the base class is still public - even though you can't create any
objects from it - which means I still get a 'cannot expose a Friend type
outside of the Public class' exception when I do this...

Friend Class X
...
End Class

Public MustInherit Class Y
Protected m_X1 as X
End Class

So, now that I've (hopefully) explainied myself better, can I do this. I
don't want class X to be public but I want m_X1 to be accessable to classes
that inherit from Y. Can this be done?

Out of interest, so long as you make the base class abstract, what does
it matter if it's public?
 
I hope that you are aware that there are many classes in the framework that
are lightly documented because they cannot be instantiated or used by the
end user (you). They are public. They are abstract.

You aren't complaining about them. Why would someone complain about you?


--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
 
Back
Top