Summary
In this chapter, we've taken a detailed look at the services feature in the Java module system. We've learned the disadvantages of tight coupling of modules, and how loose coupling provides more flexibility. We then dove right into the syntax of creating and using services and then implemented a sorting service with two provider implementations. We then looked at some advanced concepts related to services, such as mechanisms for prioritizing service instances, using the service interface itself to handle service lookup, and deferring service instance creation using the Provider type in the case of heavy-weight services.
We then revisited the two goals of modularity--strong encapsulation and dependency injection--and evaluated how ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access