D wrote:
I was reviewing these vb.net classes which deal with user logins,
logouts, cookies etc etc.
I noticed that in the Page_Load function of a user control the code
calls into another library like so
Call AnotherClassLibrary.AnotherClass.UserLogin(userId)
I do not understand how this code can call this function without
first creating an instance of the AnotherClass.
What is it that I am not understanding?
UserLogin is a *Shared* (static in C# speak, and a lot of the docs)
method of AnotherClass.
Shared members belong to the class-as-a-whole, rather than to
individual instances of the class, which is why you don't need an
object to invoke them on. Shared members exist as a way of putting
class-specific functionality logically 'in' a class definition.
For example, consider the Screen class. Instances of this class
represent actual screens, so for example WorkingArea is a non-Shared
(instance) property - it is a property of an actual Screen.
But consider the method FromPoint that takes a Point and returns a
Screen. Given the OO concept of encapsulation, the only sensible place
for this function to be defined is in the Screen class, but it doesn't
make sense for it to be an instance member. So it is defined as a
Shared member:
Public Shared Function FromPoint(ByVal point As Point) As Screen
and is invoked as Screen.FromPoint.
--
Larry Lard
Replies to group please