|
-
Jul 14th, 2004, 03:56 PM
#1
vb.net .vb files
If you can write all your classes in a single file in .net because you can declare classes unlike VB6, what are reasons you would have multiple class files in your application?
I can only thing of 2 and that is
1) if you have a ton of classes it can help to organize them (but so do code regions)
2) so you could use them in another project by just adding that .vb file that contains the class in it
if there are other reasons please let me know, just trying to figure out the best way to organize code going forward developing in .net
-
Jul 14th, 2004, 03:58 PM
#2
Id only do it if I wanted to have multiple classes under the same namespace for reasons of similarity. otherwis. id keep em seperate.
-
Jul 14th, 2004, 04:00 PM
#3
could you explain a little more
-
Jul 14th, 2004, 11:46 PM
#4
Your reasons are mostly right.
What I believe the poker is basically saying is that it would be logical to have Class X and Class Y in the same .VB file if you've created your namespace, and want X and Y to fall under that namespace. Otherwise, if they're simply classes for your app, you can avoid the cluttered code (Code regions don't do that much anyways) by placing them into separate files.
-
Jul 15th, 2004, 01:26 AM
#5
Also, consider a Form like MyForm.vb
Public Class MyForm
Inherits Form
.
.
.
End Class
When you double click this in the solution explorer the designer opens.
If you add a new class in the bottom of that file, you only get the code when double clicking, becase the IDE doesn't see it as a regular form anymore.
At least, thats with 2002.
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Jul 15th, 2004, 01:43 AM
#6
Sleep mode
I can't see any other advantages than what you've mentioned . Under organization , you can have your base class in a .vb file and each of the inherited classes in separate files , Enums or Structs in an other file , would be more organized . and so on . Just see any source code for these big projects in sourceforge and mimic the way they put classes together .
-
Jul 15th, 2004, 08:23 AM
#7
when you should make a namespace? should every .vb file that contains classes you wrote generally be under a namespace for easy access to it?
-
Jul 15th, 2004, 08:58 AM
#8
PowerPoster
This is another major reason for seperating each class into a seperate file.
3. When working on a multi developer project, if each class is in a seperate file, you can check out only one class that you are working on, and not 50 since VSS will lock the file, not the class.
That right there is the MOST important reason for seperation. If you don't work with other developers in a source controlled environment, then you don't need to.
By the way, if you have the same namespace in different files, those classes are still in the same namespace, they are just seperated out into seperate files. So the argument of keeping the classes in the same namespace doesn't hold up.
I will only put two or more classes in the same code file only if those classes are tightly coupled, and they will never be seperated.
Still, when you have a big project, and you are trying to find a class, I hate searching through different files trying to find it. It is so easy if each file represents a class. You just find the file, double click it, and you have your class.
Just my thoughts..
-
Jul 15th, 2004, 09:33 AM
#9
look at it this way. Say you have four classes Called:
Eyes
Ears
Nose
Mouth
It might be logical to group them under 1 namespace called Head. namespaces are just an organizational thing.
By the way, if you have the same namespace in different files, those classes are still in the same namespace, they are just seperated out into seperate files. So the argument of keeping the classes in the same namespace doesn't hold up.
Well I didnt say they HAD to be in 1 file. But its much easier to find the class you want under a namespace rather than dig through multiple files to find the right one.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|