How to hide classes that must be inherited from?

  • Thread starter Thread starter Marc Sommer
  • Start date Start date
M

Marc Sommer

Hello to all,

Problem: I don't want, that classes that must be inherited of could be seen
by other "hierarchies".
For instance, when I import Namespace Project.DataAccess I only what to see
the class c and not the class c_base.
Is there a way to do this? If I make c_base friend and c public, c cannot
inherit from c_base as it makes the underlying class accessible.

folowing an overview of a project structure:

Imports Project.BusinessFacade

Namespace Project

-----------------------------------
Imports Project.BusinessRules

Namespace Project.BusinessFacade

Public Class a Inherits a_base
Public MustInherit Class a_base

-----------------------------------
Imports Project.DataAccess

Namespace Project.BusinessRules

Public Class b Inherits b_base
Public MustInherit Class b_base

-----------------------------------
Namespace Project.DataAccess

Public Class c Inherits c_base
Public MustInherit Class c_base

-----------------------------------
Namespace Project.Data


Is there a solution?

Thanks for your help in advance

Marc Sommer
 
Hi

Thanks for your quickly reply!

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to define a class
baseCls and a derived class devCls, and you hope only the devCls will be
seen.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think we can not do that. According to the derivation thinking of class,
if class baseCls can be derived by class devCls. Then devCls should have
the access to the baseCls. Then when we use the devCls in another place,
that is to say, in the place we will have the access to the devCls so we
will have the access to the baseCls.

Do you have any conern about expose the baseClass to others? What do you
wants to achieve, maybe there will be another solution.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hello Peter,

thanks for your answer, you got it it the rigth way. I do not want the base
classes to be exposed in any other namespace than they are declared in
(Project.DataAccess).

There are 2 reasons for this.

a) At every time, other layers of the application should only work with the
derived classes as they provide custom methods not declared in the base
class (I think thats why there is oop ;-) )

b) In the namespace Project.DataAccess there is quite a huge amount of
classes, and the base classes get mixed up with the derived classed when
using intellisense somewhere in the project using one of these classes. So,
I only want the derived classes to get shown in intellisense, to keep things
easy and to asure that only the derived classes are geting used.


Is there a way around this?

Thank in advance, again.

Marc Sommer
 
Marc Sommer said:
Hello Peter,

thanks for your answer, you got it it the rigth way. I do not want the base
classes to be exposed in any other namespace than they are declared in
(Project.DataAccess).

There are 2 reasons for this.

a) At every time, other layers of the application should only work with the
derived classes as they provide custom methods not declared in the base
class (I think thats why there is oop ;-) )

If your base class doesn't have methods that its derived classes do,
then they cant be called from an instance of the base class.i.e. dont
declare instances of your base class. You can put Protected access
modifier on base class members to ensure only derived classes can use
them including the constructor to prevent instances of the base class
being created by anything other than a derived class.
b) In the namespace Project.DataAccess there is quite a huge amount of
classes, and the base classes get mixed up with the derived classed when
using intellisense somewhere in the project using one of these classes. So,
I only want the derived classes to get shown in intellisense, to keep things
easy and to asure that only the derived classes are geting used.


Is there a way around this?


May be there is an attribute that does this. I know you can prevent
properties from showing up in the designer with attributes Im not sure
about intellisense though? Besides the intellisense will only show
properties available to an instance of whatever class your using
right?

Intellisense/ background complilation will flag any statement trying
to access a protected member from a class other than a base class...
so the developer will be aware. As for hiding it... try attributes but
i think you might be struggling. Its kinda the whole point of
intellisense?

hth

Richard
 
Hello Richard,
If your base class doesn't have methods that its derived classes do,
then they cant be called from an instance of the base class.i.e. dont
declare instances of your base class. You can put Protected access
modifier on base class members to ensure only derived classes can use
them including the constructor to prevent instances of the base class
being created by anything other than a derived class.



May be there is an attribute that does this. I know you can prevent
properties from showing up in the designer with attributes Im not sure
about intellisense though? Besides the intellisense will only show
properties available to an instance of whatever class your using
right?

Intellisense/ background complilation will flag any statement trying
to access a protected member from a class other than a base class...
so the developer will be aware. As for hiding it... try attributes but
i think you might be struggling. Its kinda the whole point of
intellisense?


yep, it is. But I haven't found a way to get around it, at the moment. I
will see if I can find any attributes which allow hiding classes from been
seen by any intellisense routine.

Marc
 
Hi Marc,

Thanks for your quickly reply!

Based on my research, unfortunately the VS.NET 2002 and 2003 does not
support the feature to hide a class from intellisence.

As for your concern on the feature to hide a class from intellisence, you
may try to submit a wish to out mswish website.

Microsoft offers several ways for you to send comments or suggestions about
Microsoft products. If you have suggestions for product enhancements that
you would like to see in future versions of Microsoft products, please
contact us using one of the methods listed later in this article.

Let us know how we can improve our products.

Product Enhancement suggestions can include:

" Improvements on existing products.
" Suggestions for additional features.
" Ways to make products easier to use.

World Wide Web - To send a comment or suggestion via the Web, use one of
the following methods:

" In Internet Explorer 6, click Send Feedback on the Help menu and then
click the link in the Product Suggestion section of the page that appears.
" In Windows XP, click Help and Support on the Start menu. Click Send your
feedback to Microsoft, and then fill out the Product Suggestion page that
appears.
" Visit the following Microsoft Web site: http://www.microsoft.com/ms.htm
" Click Microsoft.com Guide in the upper-right corner of the page and then
click Contact Us . Click the link in the Product Suggestion section of the
page that appears.
" Visit the following Microsoft Product Feedback Web site:
"http://register.microsoft.com/mswish/suggestion.asp" and then complete and
submit the form.

E-mail - To send comments or suggestions via e-mail, use the following
Microsoft Wish Program e-mail address, (e-mail address removed).
FAX - To send comments or suggestions via FAX, use the following Microsoft
FAX number, (425) 936-7329.

Each product suggestion is read by a member of our product feedback team,
classified for easy access, and routed to the product or service team to
drive Microsoft product and/or service improvements. Because we receive an
abundance of suggestions (over 69,000 suggestions a year!) we can't
guarantee that each request makes it into a final product or service. But
we can tell you that each suggestion has been received and is being
reviewed by the team that is most capable of addressing it.

All product or service suggestions received become the sole property of
Microsoft. Should a suggestion be implemented, Microsoft is under no
obligation to provide compensation.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top