Namespace features in several common languages

Source: Internet
Author: User
: This article mainly introduces the Namespace features of namespaces in several common languages. if you are interested in PHP tutorials, refer to it. A namespace provides a way to logically organize classes to prevent name conflicts.

Several common languages

C ++

Namespaces can be nested.

A nested namespace is a namespace defined in another namespace. A nested namespace is a nested scope. the name declared in the inner namespace will hide members with the same name declared in the outer namespace:

Int x = 20; namespace outer {int x = 10; namespace inner {int z = x ;}} int main () {std: cout <outer: inner :: z; // output 10 return0 ;}

C #

Nested namespace

The namespace is declared in the namespace declaration, and each namespace is separated.

For example:

Namespace N1.N2 {class A {} class B {}} is semantically equivalent to namespace N1 {namespace N2 {class A {} class B {}}}

Java

package cn.org.web3d.x3dpad

The namespace in Java means that as long as you have an independent top-level domain name, you can ensure the absolute uniqueness of your project.

Objective-C

All class names in Objective-C applications must be globally unique. Naming has always been a tough headache for Objective-C, compared with those elegant languages. Apple officially recommends that the class names prefixed with two letters be prepared for the official library and framework. for third-party developers, we recommend that you use three or more letters as the prefix to name your class.

PHP

namespace Vendor\Package\.....

It emphasizes that the first-level Vendor should be a unique identifier, which means that you must own a top-level domain name of {Vendor}. com to ensure the absolute uniqueness of your project. For example, when I thought about this, I immediately registered a meanir.com domain name to defend myself.

The above describes the Namespace features of namespaces in several common languages, including some content. I hope my friends who are interested in PHP tutorials will be helpful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.