Re: Package == NameSpace?
Mark Space wrote:
Miles wrote:
Are they pretty much the same?
No. Packages also define a relationship between classes like C++ friend
classes. The default access is package, which means only package
members can access that method or field.
There are some superficial similarities. I think you should be on the
lookout for differences however. Assuming they are the same might trip
you up.
There's probably more differences, but I'm not up on C++ namespaces, and
I don't want to go digging through Stroustrup right now to find out.
One thing that is particularly confusing is that "nested" namespaces
don't have an equivalent in Java.
eg, package org.widgets does NOT contain package org.widgets.foo. There
has been talk about allowing a hierarchy of packages in future Java
versions, but I don't know the status of this. I can't even find the
link on Google.
Packages *do* help to partition the names, so they serve a similar
function in that regard. Also there is no such think as anonymous or
unnamed packages in Java. They can also be used to represent a concept
or aspect of your domain that requires more than one class to cooperate
in order to maintain invariants. Although in practice that usually
means too tight of a coupling between said classes.
Hope this helps,
Daniel.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>