Stephane Richard wrote:
> dont stop at telling me this is a bad design. Contrary to
> popular belief global variables are a bad design pretty much in any
> programming language. Tell me why it is bad, and how to make it better.
Ok, here's another view on the question: We can think of the five
packages as a cohesive functional group. This is indicated by your
already-considered opinion that the global variable is necessary,
to be shared equally among the five; and presumably (although you
didn't mention it), there are any number of *other* packages in the
application that do *not* (directly) access the global data -- only
the five packages.
This suggests a child hierarchy, where the five packages are children
of a common parent, and the latter declares the data. By making the
data private, you assure that only the children can have visibility,
thus limiting the globalness to only the relevant set of cohesive
packages. This language mechanism allows a higher-order encapsulation,
and as a designer, you can think of the parent and five children as
a sort of a mega-package that supports the remainder of the application.
C. Daniel Cooper ==========v=================v=======================v
Adv Computing Technologist | processes | All opinions are mine |
206-655-3519 | + architectures | and may not represent |
[log in to unmask] | = systems | those of my employer. |