Search code examples
.netscopefriendprotected

Need clarification on scope of Friend and Protected Friend


Okay, I'm having some headaches regarding the Friend and Protected Friend qualifiers. The information I read everywhere looks like legal language to me. Some like simpler legal language, but still legal language.

So, I'll try to provide a framework of thought in pseudo-VB:

Suppose I have AssemblyOne:

Public Class classA_One
  Public memberPub
  Private memberPriv
  Protected memberProt
  Friend memberFri
  ProtectedFriend memberProFri
End Class

Public Class classAB_One
  Inherits classA_One
  ...
End Class

Public Class classC_One
  Dim objA_One as classA_One
End Class

Someone else (a colleage) takes my generated .dll, references it, and creates AssemblyTwo:

Public Class ClassAD_Two
  Inherits classA_One
  ...
End Class

Public Class classE_Two
  Dim objA_One as classA_One
End Class

What I want to know is the visibility of the members of classA_One. I am sure that:

  • memberPub is visible everywhere
  • memberPriv can be seen only within classA_One
  • memberProt can be seen in classA_One, classAB_One, and classAD_One

What I'm not sure is the visibility of the other two members of classA_One.

Can someone help me?

TIA.


Solution

  • Friend: means that it is accessible to any type inside your assembly no one referencing you assembly will be able to see it.

    Protected Friend: means that the type is only accessible by derived members or your assembly types not derived or not part of your assembly will not be able to access it.

    memberFri: is accessible to classAB_one and all other in assembly classes

    memberProFri: is accessible to classAB_one but not in classC_one