O'Reilly logo

Modular Programming in Java 9 by Koushik Kothagal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required