0

We are developing a library for our company's other teams. I'd like to design an Authentication interface, if the user of our library implement that interface in their project, then we will use their implementation (probably through reflection) to do the authentication. If there is no implementation then we will ignore this part.

The reason we do like this vs. providing method to register their auth class is we don't expose these kind of high level function to the project team. They will mostly work on the business logic part.

superche
  • 753
  • 3
  • 9
  • 21
  • Possible duplicate of [Find Java classes implementing an interface](https://stackoverflow.com/questions/435890/find-java-classes-implementing-an-interface) and https://stackoverflow.com/questions/347248/how-can-i-get-a-list-of-all-the-implementations-of-an-interface-programmatically – HPCS Dec 06 '18 at 20:55
  • Reopening because this question is asking about an interface under the OP's control rather than an arbitrary third-party one. – chrylis -cautiouslyoptimistic- Dec 06 '18 at 23:59
  • This question is exactly like this and the answer provide all possible solutions: https://stackoverflow.com/questions/347248/how-can-i-get-a-list-of-all-the-implementations-of-an-interface-programmatically , so I would say its clear duplicate. – HPCS Dec 07 '18 at 08:12

1 Answers1

1

You probably want the Java Service Provider Interface; it's designed for exactly this kind of scenario. It does require the plugin creator to list the plugin class in a well-known file, but anyone who's writing custom plugins for your library can handle that part.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152