My Java library provides an interface SomethingClient
with one implementation class SomethingClientImpl
. The interface contains methods that would be called by the app, as you'd expect.
But there is a "mirrored" interface SomethingHandler
, which contains methods that are provided by the app - application callbacks. You can imagine the app provides to the library, an object of this interface - perhaps to the Factory method from which SomethingClient
is gotten.
As an unexperienced Java designer, I'm interested to know whether there is a name for, and whether/to what extent is recommended, to also provide an interface and class that combines both concepts:
public interface SomethingClient { /*..*/ }
public interface SomethingHandler { /*..*/ }
public interface ClientAndHandler extends SomethingClient,
SomethingHandler { }
public abstract class ClientAndHandler_Impl implements ClientAndHandler {
final SomethingClient clientImpl_;
ClientAndHandler_Impl(SomethingClient clientImpl) {
this.clientImpl_ = clientImpl;
}
// TODO now all SomethingClient methods are implemented in terms of clientImpl_
// AND, SomethingHandler methods are left abstract so they are implemented by the application
}
The intent is, the application writer might prefer to extend from the ClientAndHandler_Impl
abstract class and implement the callback methods, perhaps in terms of the client (outgoing) methods. This can be done with relative ease. Assuming you'd do it, what name would you give to the ClientAndHandler
concept?
Aucun commentaire:
Enregistrer un commentaire