Neeme Praks wrote:



The reason here is that the two work interfaces are very closely related, but nevertheless they are two different interfaces and it would be undesirable to merge the two interfaces. My current workaround (with Fortress) is to separate the interfaces and to use DelegatingTimeProvider as the TimeProvider implementation:


public interface TimeProvider {
   final static String ROLE = TimeProvider.class.getName();
   Date getTime();
}

public interface MutableTimeProvider {
   final static String ROLE = MutableTimeProvider.class.getName();
   void setTime(Date time);
}

public class DelegatingTimeProvider implements TimeProvider, Serviceable {
   private MutableTimeProvider timeProvider;

   public Date getTime() {
      return this.timeProvider.getTime();
   }

public void service(ServiceManager sm) throws ServiceException {
this.timeProvider = (MutableTimeProvider) sm.lookup(MutableTimeProvider.ROLE);
}
}


But this is not very elegant and requires the component developer to always write a delegating implementation whenever he/she wants to achieve this effect. And the whole issue becomes many magnitudes more complex when we increase the complexity of the inheritance hierarchy just a bit.

As an FYI, static values do not inherit. They are scoped by the enclosing interface. So in your example:

public interface TimeProvider {
    String ROLE = TimeProvider.class.getName(); // always static final
}

public interface MutableTimeProvider {
    String ROLE = MutableTimeProvider.class.getName(); // always static final
}

Will get the results you want without having to do all the workaround junk.
The value MutableTimeProvider.ROLE is different than the TimeProvider.ROLE.

Also, note that by using inheritance, you are essentially saying that all
MutableTimeProviders are TimeProviders and can be used accordingly.  You are
not implying that all TimeProviders are MutableTimeProviders, as that would
not be the case.  That is the contract you are introducing into your system,
and that should be well understood regardless of what lookup value you use
to get the TimeProvider.

There is no need to use delegating time providers, etc.

--

"They that give up essential liberty to obtain a little temporary safety
 deserve neither liberty nor safety."
                - Benjamin Franklin


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to