Friend vs Private class and public 
Author Message
 Friend vs Private class and public

I am creating a VB com dll, which contains some classes that I want to keep
hidden to other apps. I have set the instancing to Private but I was
wondering if it was good practice to set the properties and methods to
Friend (they are all early bound), or just keep them as public. I understand
that setting the instancing to private will stop the class being accessible
outside the dll, so these will achieve the same result (I think).

Are there any benefits/problems with Private Class\Public Properties, and
Private Class Friend properties? (apart from eraly binding issues)

Thanks

Fenton Farthing



Sun, 22 Aug 2004 18:51:01 GMT  
 Friend vs Private class and public
On Wed, 6 Mar 2002 10:51:01 -0000, "Fenton Farthing"

Quote:

>I am creating a VB com dll, which contains some classes that I want to keep
>hidden to other apps. I have set the instancing to Private but I was
>wondering if it was good practice to set the properties and methods to
>Friend (they are all early bound), or just keep them as public. I understand
>that setting the instancing to private will stop the class being accessible
>outside the dll, so these will achieve the same result (I think).

>Are there any benefits/problems with Private Class\Public Properties, and
>Private Class Friend properties? (apart from eraly binding issues)

Fried methods and properties are only available in the project that
they are declared in, as you point out.  Seeting an entire class to be
private basically makes all the methods and properties of that class
Friends.

Use Friend in a Public class, where you want to restrict access to
*some* methods or properties.  If you use a Private class, then
setting a method/property to Private will mean that no other classes
in the same project can see it.  Here's a little chart for you:

Class Status    Method Status   Scope
Private         Private         Only declaring class
Private         Public          Only class in same project
Private         Friend          Only class in same project
Public          Private         Only declaring class
Public          Public          Any class, anywhere
Public          Friend          Only class in same project

So you see that using Friend only affects things in public classes.

In other words, it will make absoultely no difference whatsoever.

The only thing I'd say is that if there is a *possibility* that the
Private class may ever become public, then use Friend to hide
properties/methods that must NEVER be seen - this will save you time
later, when you make the class public (you won't have to wade through,
working out which should be Friends, having forgotten the details).

James



Sun, 22 Aug 2004 21:42:48 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Public Method in a class calling a private method in same class yields ByRef error

2. Friend vs Public

3. Friend vs Public

4. Declaring variables as Static vs Private/Public -- XML

5. Private Resultset vs. Public Resultset

6. Public or Private instance of class ?

7. Public vs Private

8. Option Explicit vs. Private/Public - Newbie

9. VB5: Option Private Module vs Public

10. Private vs Public functions & subs

11. Private Resultset vs. Public Resultset

12. Placing an control in a class module as public or private property

 

 
Powered by phpBB® Forum Software