Chris Smith said:
Riippp ...
The primary purpose of a package is to avoid naming conflicts. Teeaaarrr ...
Packages also play a role in access control specifiers and in the Java
security architecture with package sealing. These are secondary to the
main purpose of a package.
Hi, Chris!
Yes, a namespace is a collection of unique names, and a package is the
Java implementation of a namespace, but it seems odd to describe this
as the primary use of packages (let's call this the name-collision use).
Surely, that packages encapsulate closely-related classes from other,
less closely-related classes is the primary use of packages in Java
(let's call this the encapsulation-use).
To take an extreme example: let's say we have 100 classes, three of
which have the same name, "Sausage." If the naming-collision use were
the primary use, then we could divide our system into three packages:
one will have 98 classes, and other two will have one class each.
Most Java I have seen, however, divides the system into packages in
which the implementation of related functionality is hidden away from
the rest of the system; the package name is sort-of a short-hand for
the contained functionality.
OK, so this is so extreme as to be stupid: and you said that the
name-collion use was the, "Primary," use, not the, "Only," use. But,
from your signature, you're a Java-course designer: so if you're
teaching kids Java and you could only tell them one use for Java
packages, would you tell them the name-collision use, or the
encapsulation-use? And doesn't this decide what use is primary?
May your battles be as savage as they are victorious, as our Klingon friends say,
..ed
www.EdmundKirwan.com - Home of The Fractal Class Composition