on 4/3/02 8:51 AM, "Geir Magnusson Jr." <[EMAIL PROTECTED]> wrote:
>> http://jakarta.apache.org/avalon/framework/inversion-of-control.html >> > > I knew that's what the Avalon-ers call it, and that's where the idea came > from, but I didn't want to stir that up... Part of the problem with this Avalon design *IMHO* is that you more easily risk an NPE...for example, in the above URL, it has the following code: class MyComponent implements Component, LogEnabled { Logger logger; public enableLogging(Logger newLogger) { this.logger = newLogger; } myMethod() { logger.info("Hello World!"); } } Now, if the parent instantiates MyComponent and forgets to call enableLogging() *before* myMethod() is called, an NPE will be thrown and it will not be clear as to why that NPE was thrown unless you go and look at the source code. There is no open coding contract that says that enableLogging() needs to be called first. If you don't want the NPE to be thrown, then every time you want to log, you would have to do something like this: if (logger != null) { logger.info("Hello World!"); } A real pain in the ass. I really don't understand why that is better than the Pull model which would be more like this: class MyComponent implements Component, LogEnabled { private static Logger logger = Log.getLogger(); myMethod() { logger.info("Hello World!"); } } Seems so much cleaner of a design to me and it is impossible to get an NPE. -jon -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>