namespaces provide a way to logically organize classes to prevent naming conflicts.
Several common languages
C++
Namespaces can be nested
Nested namespaces are namespaces that are defined in other namespaces. A nested namespace is a nested scope, and the name of the inner namespace declaration hides the member with the same name as the outer namespace declaration:
int x =;
namespace Outer {
int x = ten;
namespace inner {
int z = x;
}
}
int main ()
{
std::cout << outer::inner::z;//output:
0;
}
C#
Nested namespaces
namespace declaration, where the namespaces are declared with the "." Separated.
For example:
Namespace N1. N2
{
class A {}
class B {}
}
is semantically equivalent to
Namespace N1
{
namespace N2
{
class A {
}}}
Java
Package Cn.org.web3d.x3dpad
Namespaces in Java mean that you can guarantee the absolute uniqueness of your project as long as you have a single top-level domain.
Objective-c
All class names in the OBJECTIVE-C application must be globally unique. Naming has always been Objective-c's mishap, compared with those of elegant language. Apple has officially suggested that the two-letter prefix class name is for the official library and framework, and that as a third-party developer, the official recommendation is to use 3 or more letters as prefixes to name our class.
Php
Namespace vendor\package\ ...
It emphasizes that the first level of vendor should be the uniqueness of the logo, meaning that you have to have a {vendor}.com top-level domain name, you can guarantee the absolute uniqueness of your project. For example, when I think about it, I immediately register a meanir.com domain name to defend myself.