I am working on a project where I have a class library with about 50 different classes in this library. In my application, is it better to import the specific classes that I need for that particular form or module or is it better to just import the entire namespace even if I only need a few of the classes? Over the course of the app I will use them all, but will only use a few for each form or module.
For example:
Imports ProjectClasses 'This namespace has approx 50 classes with in it
Public Class formMain
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objProject = New CProject
Dim objElement = New CElement
End Sub
Is it better to just import the particular class vs the entire namespace?
Imports ProjectClasses.CProject
Imports ProjectClasses.CElement
Public Class formMain
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objProject = New CProject
Dim objElement = New CElement
End Sub
It sounds like the answer should be neither. Your library should probably be broken down by area/project/functionality, and then you should be importing whatever you need for a particular project.
If that’s nt feasible, then import the whole namespace — if this causes problem you have probably picked some bad class names.