|
-
Mar 4th, 2002, 06:10 AM
#1
Thread Starter
Addicted Member
organising code
now that you can create class files pretty much anywhere in VB code, what would be the best way to organise them? for example, in form1.vb you have the form1 class, but you could also have several other classes in that file as well. so would it be best to have any form classes in their own file, and any other classes in class files? also, when would you decide to use namespaces? would that just be if you have a bunch of classes that relate to a similar thing, and would you typically have each namespace in a seperate class file?
i know these are pretty simple questions, but i feel i must ask them. thanks
-
Mar 4th, 2002, 07:03 AM
#2
Frenzied Member
Namespacing comes from c++
and from what i gathered and learned its best to namespace things that are related
for example
if i have a Namespace called MyArrays
then i will have all functions related to arrays in here
such as quicksort, heapsort, binary and so on
so to answer your question, its frowned upon when you namespace unrelated things
that is what i learned and heard anyways
-
Mar 4th, 2002, 07:14 AM
#3
Thread Starter
Addicted Member
ok, thanks, that answers one of my questions. how about where to create classes/namespaces?
-
Mar 4th, 2002, 09:20 AM
#4
like this..in any .vb file
Code:
Namespace mySpace1
Class myClass1
'beeotch
End Class
Class myClass2
'beeotch 2
End Class
End Namespace
-
Mar 4th, 2002, 09:55 AM
#5
Thread Starter
Addicted Member
Cander, yeah, but you wouldn't just start shoving classes all over the place would ya? i know it's basically down to preference where you put them, but would you normally create classes in class files, rather than in a form file?
-
Mar 4th, 2002, 09:55 AM
#6
Hyperactive Member
now that you can create class files pretty much anywhere in VB code, what would be the best way to organise them? for example, in form1.vb you have the form1 class, but you could also have several other classes in that file as well. so would it be best to have any form classes in their own file, and any other classes in class files?
Personally I would leave the form class in a .vb file on it's own, and then have another .vb file for each other class. I would however consider have one .vb file for all classes in a specific namespace (see Canders example).
I guess the main consideration is making it easy for the programmer to find the code for any specific class without having to search through too many vb files. It should be fairly obvious where they have been defined. (imho).
-
Mar 4th, 2002, 09:57 AM
#7
like I said , put it in a .vb file.
in .net you dont have seperate file extensions for class/modules/forms.
its all .vb.
-
Mar 4th, 2002, 10:02 AM
#8
Thread Starter
Addicted Member
ok, thanks, that's cleared that up for me. i know that it was a pretty simple question, and i kinda knew that's how it worked, i just wanted to make sure.
-
Mar 4th, 2002, 10:04 AM
#9
Hyperactive Member
in .net you dont have seperate file extensions for class/modules/forms.
No you don't - but that doesn't mean you have to lump them all into one .vb file. Personally I still like to separate them out a little.
I also still tend to prefix my .vb files with f or c to denote if they contain class structure(s) or a form class structure. I know to .net they are all classes - but I find it easier to maintain my apps buy doing this. I appreciate that this may just be personally preference.
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
|