Calling broker pattern
This article publishes a draft of a previously unreleased object-oriented design pattern |
The Calling Broker pattern enables true multimethods (multiple dispatch) in Java (which is not possible otherwise due to the design of the Java programming language), dispatches on method level by any arbitrary context and can be used on top of any creational pattern, such as dependency injection.
This means that it can be introduced into an existing and matured project, which faces new functional requirements leading to the need for a multiple dispatch technology. Think of a business application with a complex business logic, where the behavior shall depend on different parameters, e.g. the product (or contract) category, the concrete product (or contract) type, the country of the customer, the branch office (or subsidiary) that customer is assigned to, the rating or category of that customer (gold, silver, bronze, ...), etc.
The dispatch could be implemented with conditional statements (if ... then ... else ..., switch ... case ...), but in a large application with complex business logic this will decrease the maintainability of the code, often dramatically and often causing significantly higher efforts for the maintenance and the future implementations of new functionalities as well. Given that the dispatch shall take place for each concerned use case in many places of the code with a few varying parameters, it seems to be inappropriate to use a rules engine for that dispatch in general (somewhat depending on the rules engine).
Here the Calling Broker pattern comes into play and can help to save or improve the maintainability of that project. Moreover it decouples the implementations of context dependend behavior from the default behavior and from the callers of that context dependend behavior. This allows to add and to remove such context dependend behaviors way easier and way cleaner than with conditional statements or the like. See also https://en.wikipedia.org/wiki/Open–closed_principle.
For further details please download and open the document below.
|
About the creator & author