Namespace

The namespace ( namespace English ) is a term used in programming. Here are - especially in object-oriented programming - arranged the names for objects in a kind of tree structure and clearly addressed via appropriate path name.

Simple terms this means that each name uniquely identifies an object within such a space. However, the same name can be freely used to refer to a different object in a different namespace again. In addition, these independent namespaces can be connected within a hierarchy.

Technical details

A name identifies an object. However, for the unique assignment is the appropriate context - the namespace - must be observed. The description is done in programming usually described by the so-called " dot notation ", where analogous to a tree structure, the individual objects and their properties (attributes ) and methods are addressed. In addition to the dot notation but other characters are used, as for example in file names with slashes ( "/") or backslashes ("\ "). Some namespaces ( eg, file systems ) are hierarchical, that is, they can in turn consist of namespaces. Namespaces are used to avoid conflicts when assigning names. Graphically are namespaces with trees equivalent, ie they have a root ( a fixed, defined starting point ), nodes (directories) and leaves (objects).

The idea of namespaces is also used in other areas by other names, such as in telephony. Each participant will receive an individual number (eg 4711 ) and this is awarded locally. The telephone network is here divided into sub- networks and the identification is performed by the code. Thus, each number can be assigned more than once, it must be unique within the subnet. When a call is in the same area code thus extends the indication of the number 4711th If a participant from the area code 0815 can be contacted, which also has the number 4711, we will select the 0815. By this technique, a plurality of subscribers may have the same telephone number 4711. In this example, the namespace 0815, 4711 the actual name, and the target telephone line would be the identified object.

When creating programs, an author using namespaces write great software packages with many distinguished names, without having to worry whether the newly introduced name conflicts with another name. In contrast to the situation without namespaces not the whole name here newly introduced, but only part of the name, that of the namespace.

A namespace is a declaratory area that attaches an additional identifier to any name that was declared in it. This additional identifier makes it less likely that a name conflict occurs with names that have been declared elsewhere in the program. It is possible to use the same name in a different namespace without conflict even when the same name is present in the same translation unit. As long as it appears in different namespaces, each name is unique because of the added namespace identifier.

Most modern programming languages ​​support namespaces. The XML markup language also supports namespaces, the prefix is ​​separated by a colon from the local name.

Examples

C

Namespace A {      class X { / * ... * /}; }   namespace B {      class X { / * ... * /}; }   int func1 () {      A :: X object1 (); / / Instance of class X from namespace A      B :: X object2 (); / / Instance of class X from namespace B }   int func2 () {      using namespace A;        X object1 (); / / Instance of class X from namespace A      B :: X object2 (); / / Instance of class X from namespace B }   func3 int () {      using namespace B;        A :: X object1 (); / / Instance of class X from namespace A      X object2 (); / / Instance of class X from namespace B }   func4 int () {      using namespace A;      using namespace B;        X object1 (); / / Error: reference to X is ambiguous } Namespaces may be nested in C also:

Namespace nested1 {      namespace nested2      {          namespace nested3 {/ * ... * /}      } } PHP

Namespace vehicle \ car; Use drive \ Engine;   class small car {        protected $ engine;        public function __ construct ( $ engine engine) {          $ this -> engine = $ engine;      }   } Public namespaces

  • Domain Name System (DNS) XML namespace

For public namespaces there especially the problem of managing, for all (market) participants must agree, so no name refers to two different things. For this reason, there are usually management organization which manages the namespaces or portions thereof and book excerpts of it for individual participants. Here again there is the problem that this administration organizations themselves have a monopoly position in the rule so that they could achieve monopoly prices to the detriment of the participants in profit orientation. In addition, provides such a monopoly a weak point, because in case of failure of the administrative organization can be significantly disrupted, depending on integration of the participants of the business operations of these participants. This applies not only, but also for the domain name system, because the name resolution needs to happen in this case online.

591612
de