Package versus Namespace

From CSSEMediaWiki
(Difference between revisions)
Jump to: navigation, search
m
m (Reverted edits by Ebybymic (Talk); changed back to last version by Matthew Harward)
 
(2 intermediate revisions by 2 users not shown)
Line 15: Line 15:
  
 
  package a.name.space;
 
  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.
 
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.

Latest revision as of 03:11, 25 November 2010

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