What is a Gateway pattern?

I’m not talking about a Gateway to another dimension (as pictured above), I know what they are and I can use them without any problems.  I’m talking about the design pattern Gateway, it suddenly popped up in a project and I wasn’t sure what the heck it was.

There can be occasions when working with developers, they will start using some terminology or design pattern which you either don’t know or can’t remember.

This can be a bit awkward because you can feel like a bit of an idiot and the other person was talking about it like it’s something everyone knows.

  • If knowledge is power, I view a lack of knowledge as an opportunity to learn and another step towards becoming all powerful (MWHHAHAHAHAAHAAA – evil laugh)
  • Don’t be embarrassed about not knowing something, it is in fact impossible to know everything.
  • Grab the opportunity to learn something from someone who knows about it.  They won’t look down on you and 99 percent of people will be happy to help and explain it to you (because it makes them feel great being the teacher/master).
  • It’s often easier to understand from a person rather than reading it from a book/article because you can ask questions and clarify areas of confusion
  • Always try to keep learning and if you don’t understand something, don’t sit quietly, hiding in the corner, be proactive and learn that piece of information, you never know when it may come in useful in the future (when you really need it).

I am reading Josh Waizkins book, the art of learning

He focuses not on winning/losing but always learning from both, in some ways this is similar to not knowing something or knowing a certain piece of knowledge.

  • Knowing – you can explain to someone else plus there is usually more to learn
  • Not knowing – don’t be embarrassed because you can start learning about the subject and move it from being a potential weakness into a potential strength.

Constant Learning

The life of a developer should be one of constant learning because a developer’s core skills/knowledge are in constant danger of becoming out of date as new languages/functionality constantly emerge.  To combat this developer should always be learning and building on their knowledge and skills.  I believe this is an attitude/philosphy of good developers, whilst the average/bad developers have no interest in learning (and complain about doing so) until one day the company lets them go because their programming skills are not useful in the new projects.

In CRM terms you can view this as new functionality, new releases, new Javascript frameworks, 3rd party applications integrating with CRM.  You need to try to keep up, so you have some knowledge before you need to use it in a live project.

Knowledge is incremental

I believe knowledge is incremental, you keep building on previous knowledge and you get a better understanding of new coding functionality and a more in depth understanding of functionality/code you already new about (but now armed with more knowledge you can see things you hadn’t noticed before)

Back To Gateways

The gateway pattern is a lot simpler than it sounds, but sometimes it takes great skill to describe things simply and concisely, which is why I won’t try to do that and will pass on that task.

Microsoft has a great description of the Gateway pattern, which you can find in full here

Gateway component that abstracts the access to the external resource. The gateway presents a single interface to the integrated applications while hiding the external resource interface. In addition, the gateway encapsulates any protocol translation that may be necessary to communicate with the external resource.
This diagram explains how the Gateway pattern works probably better than the description
You can see the Gateway pattern creates a single source of access (a single interface), behind it, it can offer lots of different methods.
You could consider paying for an item on amazon/ebay. The seller is only concerned with being paid but behind the payment there are lots of different methods of paying like credit card, debit card, paypal etc.

CRM and Gateway

In the CRM project I was working on, there were lots of Gateway classes in the plugin projects.

I found this confusing to begin with, the primary reason being I wasn’t sure what the Gateway design pattern was and my business knowledge of the project was not in depth.   It turned out the Gateway classes in this project were used to store mainly Linq queries for various entities used in the plugins.

This particular project used Linq queries, but in the Gateway classes it could have used QueryExpression it wouldn’t have mattered because the plugin code initiated the Gateway class and the various methods used to retrieve data.

The benefit of decoupling CRM queries into separate classes is you can reuse those classes in various plugins and test them without having to test the plugin code.