'Is there a design pattern to write a dispatcher logic that calls specific methods based on given path?

We have a use case where we need to write a dispatcher class that takes the rest request object and should call the specific methods based on the request. For example we have a class Users that has methods to get, put, delete and post user data. We have another class Ledger that has methods related to ledgers add money, send money, create, delete etc. The dispatcher should take the request object and if the path is /users/* it should call the specific method in Users class. If the path is /ledger/* it should call the specific method in Ledger class. Is there a design pattern for such use cases?



Solution 1:[1]

According to your scenario you should use facade design pattern and provide a wrapper interface on top of the existing interface to help client application.

Solution 2:[2]

you can combine factory and strategy pattern. you can create a class for each scenario and a factory class or method to decide which class should initialize..also you can create a facade class to hide implemention complexity.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fakhar uddin Malik
Solution 2 erfanmorsali