Implementing service priorities

In the last example, we got two instances of SortUtil, and we did something ridiculous with them--we sorted the list twice, once per implementation! You wouldn't typically do that. What you'll most likely need to do in applications when you receive more than one service implementation is something a bit trickier. You'll need to choose one!

Unfortunately there is no way you can give service implementations distinct priorities. So, there's no way you can say something like BubbleSortUtilImpl is your favorite sort implementation, and that's the implementation to be used if it's available, irrespective of whatever other implementations are found. As per design, it's not the responsibility of the service implementations ...

Get Modular Programming in Java 9 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.