Pattern 11 - Aggregator and facade modules

We've looked at aggregator modules in Chapter 6, Module Resolution, Readability, and Accessibility. Aggregator modules allows us to create modules that consolidate a set of libraries that are commonly used so that the consumers can require just one aggregator module rather than the more tedious process of finding the right list of modules to require. Using aggregator modules is a good pattern to use when you have multiple modules in your application that need a standard set of dependencies to be required. This not only makes the process of establishing dependencies on new modules easier, it also allows you to change and update that list of dependencies in one place and have it reflected across all other modules in your application or organization.

Following is an example aggregator module that provides transitive dependency on three other modules:

There's another pattern that's closely related that I like to call facade modules. These are an extension of aggregator modules in that they do offer dependencies to a group of modules using transitive dependencies, but they might also contain logic that deals with types from multiple modules. While aggregator modules just do transitive dependencies and do not necessarily contain logic of their own, the facade module might contain logic to do things like choose an API from one of the modules based on certain criteria, co-ordinate and synchronize calls across multiple module APIs, and so on.

Both aggregator and facade modules are designed for special use cases and act as wrappers around the underlying modules. Since they perform consolidation of modules for this reason, they may not offer the best reuse opportunities. But that's OK! Like we've discussed before, the best modules to facilitate reuse are simple single-purpose modules. However, aggregator and facade modules provide a middle ground between extremely fragmented modules that are pain to use and specialized modules that are easier to use but lack flexibility. A very handy pattern to use in such cases, when you are trying to strike that balance.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.44.143