Gateway Pattern

  1. Summary
    1. Gateway is an Application Integration patterns that is used to decouple application access to external resources.
    2. It further facilitate testing of system by placing Service Stub at the place of external resources.
    3. This pattern is very use full if service provider or external resource like database is subjected to change.
    4. There are several out of the box integration product like Host Integration Server and BizTalk server 
    5. A clear benefit of Gateway is that it also makes it easier for you to swap out one kind of resource for another.
  2. When to Use
    1. You should consider Gateway whenever you have an awkward interface to something that feels external.
  3. Overview Tutorials
    1. http://msdn.microsoft.com/en-us/library/ff647277.aspx
    2. http://martinfowler.com/eaaCatalog/gateway.html
  4. Diagram

  5. Thumb Rules
    1. Keep a Gateway as simple as you can.
    2. Focus on the essential roles of adapting the external service and providing a good point for stubbing. 
    3. The Gateway should be as minimal as possible and yet able to handle these tasks. Any more complex logic should be in the Gateway's clients.
    4. You usually set up the Gateway so that classes can find it from a well-known place.
  6. Related Pattern 
    1. Mapper: Mapper can also be used with gateway if there are multiple resources and their schema differ. 
    2. Service Stubs :Usually mimic original external resource and in general used for testing purpose.
  7. Related Implementations
    1. Host Integration Server
    2. BizTalk Server
  8. Specific Considerations 
    1. Gateway Vs Facade
      1. While Facade simplifies a more complex API, it's usually done by the writer of the service for general use. A Gateway is written by the client for its particular use. In addition, a Facade always implies a different interface to what it's covering, whereas a Gateway may copy the wrapped facade entirely, being used for substitution or testing purposes.
    2. Gateway Vs Adapter 
      1. Adapter alters an implementation's interface to match another interface you need to work with. With Gateway there usually isn't an existing interface, although you might use an adapter to map an implementation to a Gateway interface. In this case the adapter is part of the Gateway implementation.
    3. Gateway Vs Mediator
      1. Mediator usually separates multiple objects so that they don't know about each other but do know about the mediator. With a Gateway there are usually only two objects involved and the resource that's being wrapped doesn't know about the Gateway.
  9. References 
    1. http://msdn.microsoft.com/en-us/library/ff647277.aspx
    2. http://martinfowler.com/eaaCatalog/gateway.html
    3. Implementing Gateway with Host Integration Server 2004