Package versus Namespace

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
(New page: A package and namespace are two strongly related concepts in OO languages. They differ only subtly, but this distinction provides an insight into an important distinction between two parad...)
 
Line 1: Line 1:
 
A package and namespace are two strongly related concepts in OO languages. They differ only subtly, but this distinction provides an insight into an important distinction between two paradigms in OO languages.
 
A package and namespace are two strongly related concepts in OO languages. They differ only subtly, but this distinction provides an insight into an important distinction between two paradigms in OO languages.
  
== A package ==
 
  
 
== A namespace ==
 
== A namespace ==
 +
A namespace is a generic term for a container and potentially an encapsulation boundary for the classes within them. In most languages, a namespace is programmatically defined for a block of text.
 +
 +
namespace a.name.space {
 +
 +
class { ... }
 +
 +
}
 +
 +
== A package ==
 +
A package is Java specific language construct to define namespaces. Each file has a declaration of a the package that it is contained within. Each file may only be related to a single package.
 +
 +
package a.name.space;
 +
 +
By defining a whole file as part of a namespace and not having the ability to do otherwise pushes developers towards class encapsulation as the physical location of the class within the file system becomes more important than the blueprint of the object that a class provides.
  
 
== See Also ==
 
== See Also ==
 
* [[Encapsulation]]
 
* [[Encapsulation]]
 +
 +
{{Nomenclature}}
 +
 +
[[Category: Nomenclature]]

Revision as of 12:35, 10 September 2009

A package and namespace are two strongly related concepts in OO languages. They differ only subtly, but this distinction provides an insight into an important distinction between two paradigms in OO languages.


A namespace

A namespace is a generic term for a container and potentially an encapsulation boundary for the classes within them. In most languages, a namespace is programmatically defined for a block of text.

namespace a.name.space {

class { ... }

}

A package

A package is Java specific language construct to define namespaces. Each file has a declaration of a the package that it is contained within. Each file may only be related to a single package.

package a.name.space;

By defining a whole file as part of a namespace and not having the ability to do otherwise pushes developers towards class encapsulation as the physical location of the class within the file system becomes more important than the blueprint of the object that a class provides.

See Also


Personal tools