Use Cases for Shared Functions in VB.NET
Static functions in C# are comparable to shared functions or share methods in Visual Basics.NET (VB). We’ll talk about the Shared function’s use case here. Factory methods, helper functions, logger classes, access control, etc. are a few examples.
Methods in the Factory
By generating instants or objects, the Class’s properties and methods can be utilized outside. However, the function mentioned by the Shared keyword can only be utilized outside of the class name. Making a class and using the named factory Method again is a frequent application operation.
Public Class Employee
Public Property Name As String
' Factory method
Public Shared Function Create(name As String) As Employee
Dim emp As New Employee()
emp.Name = name
Return emp
End Function
End Class
Configuration Management
App configuration makes it read-only with a shared function is useful for making common database connections all over the application.
Logging
Accessing the Logger function anywhere in the application shared function can be used for logging the status of an application.
Access Control
Shared functions also can be used in access control logic for admin and user login.