I have this problem where I need to design a Java package which is used for:
- Getting data from different data sources. For example, Class A will retrieve customer data from an Oracle database, while Class B will retrieve the same information from a web service data source (via SOAP).
- The results will need to be combined, the rule for combination is quite complex, so ideally I should hide this from the users (other developers) of this package.
- When one data sources fails, I need to still return the result from other data sources. However, I also need to let the caller know one of the data sources failed to respond.
Right now I’m doing it by having a boolean value inside the Class A and Class B indicating whether there’s an error, and another object for storing the actual error message. The caller will have to check this boolean value after making a call to see whether an error has occurred.
What is a good design model for this?
The answer would be very broad, so I would suggest you to use the:
This psuedo code has similar syntax as UML and Python:
Client usage:
Unfortunately, it looks a bit complex.
OOP is based a lot on polymorphism.
So in
Dao, you let the subclass fetch data from whatever place and you just call it dao.fetch().In
Strategythe same, the subclass performs one algorithm or the other (to avoid having a lot of strangeif‘s,else‘s,switch‘s, etc.).With
Statethe same thing happens. Instead of going like:etc., etc. you just say, “Hey, this will be the code one. There are two connections and this is when there is only one.”.
Finally, facade say to the client “Don’t worry, I’ll handle this.”.