Hvis du vil have et lidt mere konkret svar, kan jeg fortælle at det er en samling af klasser, der typisk er afhængige af hinanden, eller nært beslægtede.
Namespaces are a holdover from the bad old C++ days. Since two classes or functions can conceivably have the same name, and since identical names are not allowed in the same module, and since it's quite possible that you'll want to use two different classes with the same name in one module, there needs to be a way to differentiate the two. That's what namespaces are used for.
For example, if you create a class called MyClass and I create a class also called MyClass, and FWM wants to use them both in his project, we can separate the two by enclosing them in namespaces. So to access a member function in my class, he would type:
DannySmurf::MyClass->Hello();
and to access a member function in your class he would type:
juice::MyClass->Goodbye();
Everything in C++ and C# is enclosed in a namespace, even if you don't specify one. In C++, classes and functions that are not explicitly put in a namespace are assumed to be in the std namespace. In C#, a namespace with the same name as the project is wrapped around any class that isn't explicitly given a namespace.
Namespaces begrebet hænger ikke kun sammem med classe og objectbegrebet, og dermed er omens definition alt for snæver.
Namespaces kan oversættes med den standard der er valgt for navngivning, herunder hvordan navngivningen skrives i koden og hvor mange bits den fylder. Nmamespace begrebet bruges om classer, objecter, konstanter, variabler, attributter, om protokoller og database nomenklatur, og alt anden navngivningsstandard der har forbindelse med kodning og applikationers behandling af navngivne ting.
Namespaces are typically established to distinguish between multiple interpretations of a single token or phrase. One common example; a "nut" in the "food" namespace is something to eat, while in the "hardware" namespace something to fasten to a bolt (something you would not want to attempt with a "food:nut" and vice-versa). In XML, it can be thought of as a collection of names, identified by a URI reference [RFC2396], which are used in XML documents
A standard that lets you specify a unique label to the set of element names defined by a DTD. A document using that DTD can be included in any other document without having a conflict between element names. The elements defined in your DTD are then uniquely identified so that, for example, the parser can tell when an element called <name> should be interpreted according to your DTD, rather than using the definiton for an element called "name" in a different DTD
namespace kan nemmest sammenlignes med mapper på computeren, hvor en type (klasse, struct, enum osv.) er filerne. Man kan ikke have to filer i samme mappe der hedder det samme, men sagtens have to filer på computeren der hedder det samme, bare de ikke ligger i samme mappe.
På samme måde kan man bruge namespaces (mapper) til at sortere i sine typer (filer).
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.