I was taking one of the OCMJEA mock tests, and came across this question:
Q. ABC Inc. is building a J2EE based application for Order Entry and Management. Once the order is taken, it is submitted to a relational database. A provisioning system then queries data and makes appropriate calls to various subsystems using JMS on MQ Series. What design pattern is JMS an example of here?
I answered Mediator, since it promotes loose coupling by keeping objects from referring to each other. That is what JMS on MQSeries is doing here.
But the correct answer, as per the test authors, states it is Bridge pattern where JMS is abstraction and MQ series could be the implementation. The explanation only quotes the GoF definition of the patterns in options.
Could someone please help me understand, how is Mediator pattern wrong here ? (There is only one correct answer to this question)
I think that yes, JMS can be an example of a bridge, and overall, the question is talking about the Observer pattern, but again, the question doesn't present us enough elements, we can choose Bridge by discarding all the other answers.
About the mediator pattern, this pattern uses an objet to coordinate all the communication among other objects. These objects don't communicate directly with each other, instead, they communicate through the mediator object. In this case, the question doesn't refer to a mediator object.
Thanks for your clarification about mediator pattern. And yes, this question is very vague, does not present enough information to choose a right answer or discard the close but wrong ones.
I found some posts on this question on this forum and others as well, but could not find a definite answer anywhere. I guess it's better to move on and hope such questions do not find place in actual OCMJEA tests