I am developing a library in Java where I want other Java codes to be able hook at various life-cycle.
The approach I am thinking of is define various Interfaces (for the the different hook points). At runtime discover all implementors of those classes (which are already available in classpath). Run them at the appropriate time. I could use probably use Reflections for this.
Problem with using Reflections is I am dictating an approach.
Another approach could be that I have optional dependency on these interfaces and use dependency injection (like Dagger) to inject an instance. The code using this library can then inject a concrete class which does all the Reflections magic described above and provide the functionality described there; if needed. This approach seems more flexible to me.
Please suggest if there are any other better approaches available?