开发者

Clarification of the term "Namespace"

My understanding of the term "namespace" is essentiall开发者_Go百科y that of a class; a container of methods and variables. Although that seems to be doubling up on what I consider to be the definition of a class.

Can someone confirm or clarify that belief?


I would say a namespace is a way of logically grouping symbols (classes, functions, ... depending on the exact language you're working with) in a container that ensures that those symbols don't collide with other symbols (which could have the same name) in other namespaces.


Namespace is mainly used for avoiding name conflicts. Suppose if you a class named A but this class may be defined by others . so in this cases you need to separate your class from others. In that instance Namespace is come to act. For eg: you given namespace 'using yourname ' in this name space you defined a class A. so that this class can be distinguished by yourname.A. similary for methods ,variables all thing you can defined in your own namespace.


A namespace is used to have different programming rules in the same program module. Let's say you want to define the function 'string_addition' to mean 'string1' + 'string2' = 'string1string2', but later in the same program you want to define 'string_addition' to mean 'string1' + 'string2' = 'string3'. You can use namespaces, so that in the same file you can call on the different namespaces and get both kinds of rules.

namespace h:stringadd(string1, string2) = string1string2

namespace f:stringadd(string1, string2) = string3


a namespace provides a context for an identifier you are referring to. So in that sense, a class is also a namespace.


In the general sense, a namespace defines a set of names which are unique. In other words, a name is only unique within a namespace.

As this concept applies to different languages, there are many variants that include issues like encapsulation, namepsacing, scope and so on.


A namespace is the domain in which a given name remains unique. For example you may define many classes named Widget but they must all appear within seperate domains to be uniquely identifiable from one another.

The domain in which a name appears depends upon the context in which it is defined. For example in the .NET world, a class name must be unique within a namespace, which itself must be unique within an assembly, so one could say that the domain in which a class name is unique is a namespace and the domain of a namespace is an assembly


Namespace is a group of classes. It becomes a .dll after compilation. So we can add that .dll file to our project and can easily use those classes.


Namespaces aren't a feature of OOP. Specify a programming language.

And, yes, in general they are similar to classes, but only those classes which contain no non-static members (since a namespace couldn't be instantiated to form an object).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜