R
Roedy Green
I wondered what sort of techniques you use for this sort of problem.
Lets say I have a program that processes hundreds of files. Each one
may be processed by some set of hundreds of processing modules that
may be called many times per file, for different parts of it.
In that processing code there is a need for:
one-time startup initialisation = handled by static init.
shut down = handled by Runtime.getRuntime().addShutdownHook
But what about some code that should be run every time a new file is
loaded.
Possible solutions
1. mix code from many different processors together in a newFileInit
method. All those variables must be public. This is very
unencapsulated.
2. Pass a boolean to every processor on every call to tell it if this
represents a new file. Most of the time, the boolean is of no
interest.
3. some kind of way of registering a callback that gets called on
reading a new file. Such a scheme might be easily extendable to
handle various conditions without disturbing existing code. It would
be like addShutdownHook but for more general conditions. Is there a
canned solution?
Lets say I have a program that processes hundreds of files. Each one
may be processed by some set of hundreds of processing modules that
may be called many times per file, for different parts of it.
In that processing code there is a need for:
one-time startup initialisation = handled by static init.
shut down = handled by Runtime.getRuntime().addShutdownHook
But what about some code that should be run every time a new file is
loaded.
Possible solutions
1. mix code from many different processors together in a newFileInit
method. All those variables must be public. This is very
unencapsulated.
2. Pass a boolean to every processor on every call to tell it if this
represents a new file. Most of the time, the boolean is of no
interest.
3. some kind of way of registering a callback that gets called on
reading a new file. Such a scheme might be easily extendable to
handle various conditions without disturbing existing code. It would
be like addShutdownHook but for more general conditions. Is there a
canned solution?