Why, when and where should you use namespaces?
Woof?
Printable View
Why, when and where should you use namespaces?
Woof?
A namespace is basically a logical grouping of classes, you already know. You use them in order to avoid conflicting code, you use them to logically organize your classes.
Whenever you write a class for a class library, it's best to give it a namespace. Reason: So that if anyone else wants to use it, they have an idea what it's about.
Pretty simple answer though, do you have any specific Q?
So...a name space per function then?
Woof
Also...if I was writing some forum software...what should I call the project, and what should I call the solution?
Should I call them both "WokaForums"???
Woka
A namespace for a GROUP of classes, then. :)Quote:
Originally posted by Wokawidget
So...a name space per function then?
Woof
Call them whatever you like. Just be sure to make your namespaces "scalable" ( I wouldn't know the proper term)Quote:
Originally posted by Wokawidget
Also...if I was writing some forum software...what should I call the project, and what should I call the solution?
Should I call them both "WokaForums"???
Woka
It could be something like
Wokawidget.WebSolutions.Forums.WokaForums
Edit:
So that, in the future, if you made an email client one day, you'd name it
Wokawidget.WinSolutions.Email.WokaMail
OK, I have an example:Quote:
Originally posted by Wokawidget
So...a name space per function then?
Woof
I am currently working on the sandpaper project. I am making a Meaning Of Life generator. This generator consists of three classes for whatever reasons.
I have given it the namespace
Sandpaper.MeaningOfLife
Meanwhile, wossname would be working on the eleventh commandment, and he'd call it
Sandpaper.EleventhCommandment
which itself consists of say, 15 classes.
See where I'm going?
.... also
one of your developers decided to incorporate widgets from WobblyWidgets - guess what? They also developed code for MeaningOfLife (it's a very popular area of software engineering right now!)
But because there's is in the namespace WobblyWidgets there is no conflict because its WobblyWidgets.MeaningOfLife.
Yes, but you really have to wonder about this trend. They all end up giving us 42 as an answer anyways. :p
Ah!! But now you can use polymorphism and also get the answer Mice!!!