The situation is this: You have two classes that both implement the same interface and both classes work together to complete some business process.
For example networkUserManager and localUserManager implement IUserManager which has a method getUser(). networkUserManager.getUser() puts a request to get a User on the queue and returns the reply. localUserManager.getUser() gets a request off the queue, finds the user information in some database, and then replies with the user data.
When I saw something similar to this being done, I couldn’t help but wonder if this was bad design. Is this bad design and if not what is an example where doing something like this would be a good idea?
You seem to be describing the Decorator pattern. In this case, the
NetworkUserManagerprovides additional functionality over that provided by theLocalUserManager. You don’t say what language you’re using, but this pattern appears throughout thejava.iopackage.On the other hand, your description of
LocalUserManager.getUser()pulling a message off the queue seems wrong — it’s backward from the wayNetWorkUserManagerworks. I would see this as being a proper decorator ifLocalUserManageraccessed the database, in response to something else (perhaps aNetworkUserManagerService) invokinggetUser().