So by null object, you mean an object which implements the LogService interface but whose methods are no-ops?
BJ Hargrave Senior Technical Staff Member, IBM OSGi Fellow and CTO of the OSGi Alliance [EMAIL PROTECTED] Office: +1 407 849 9117 Mobile: +1 386 848 3788 Marcel Offermans <[EMAIL PROTECTED]> Sent by: [EMAIL PROTECTED] 2006-05-11 10:16 AM Please respond to OSGi Developer Mail List <osgi-dev@bundles.osgi.org> To OSGi Developer Mail List <osgi-dev@bundles.osgi.org> cc Subject Re: [osgi-dev] Declarative Services implementation guidelines? Kevin Riff wrote: >Copying to a local variable first would also work, but only if the log >field is volatile. Otherwise you risk having your threads see a stale >copy of that field. > > >-----Original Message----- > // ... > if(log != null) { > log.log(LogService.INFO, "Did something"); > } > // ... > > In the dependency manager I've used the null object pattern to make this a bit easier for the user. Instead of "nulling" the field when the service is not available, I create a null object so you don't have to check for null everywhere. Of course you should use this combined with the volatile keyword, like Kevin suggested. The null object implementation I've used should be pretty easy to re-use (even if you don't use the dependency manager). Greetings, Marcel _______________________________________________ osgi-dev mailing list osgi-dev@bundles.osgi.org http://bundles.osgi.org/mailman/listinfo/osgi-dev _______________________________________________ osgi-dev mailing list osgi-dev@bundles.osgi.org http://bundles.osgi.org/mailman/listinfo/osgi-dev