Skip to first unread message

Andreas Schaefer

unread,
Sep 10, 2013, 9:14:46 AM9/10/13
to clean-code...@googlegroups.com
In our company we're about to (finally) go for a clean architecture. While we were discussing some best practices and concepts a naming issue came up.
Should we call them gateways or repositories?

As we think that it's the same anyway, I said to go for gateway as imo the name and semantic of repository got potentially a bit more biased in the past .. and of course UncleBob uses gateway as well ;)

but that compares repository to table-data-gateway, which didn't help very much as the 'table-data' already narrows it down to much.

What do you guys think about that, are there differences between a gateway and a repository?

regards
 Andreas Schaefer

Sebastian Gozin

unread,
Sep 10, 2013, 7:19:39 PM9/10/13
to clean-code...@googlegroups.com
I don't think there is a difference except that repository suggest storage to me while gateway suggests a channel. For example, a persistence gateway would not feel weird were it called a repository but an e-mail gateway would. As I'm actually dispatching and not storing.

Scott Burleigh

unread,
Sep 10, 2013, 9:53:18 PM9/10/13
to clean-code...@googlegroups.com

Rafael Muñoz

unread,
Sep 11, 2013, 4:45:06 AM9/11/13
to clean-code...@googlegroups.com

I prefer Gateway over Repository because of subjective reasons.

It seems to me that the Repository term has passive connotations, basically a storage of data that you can operate with..

But the Gateways can be just a dispatcher, or as I see it can even push data to the system ( ie: A Messenger Gateway implemented with an xmpp client ).

I think the term Gateway represents better all these possibilities.

On Tuesday, September 10, 2013 3:14:46 PM UTC+2, Andreas Schaefer wrote:

Sebastian Gozin

unread,
Sep 11, 2013, 5:43:01 AM9/11/13
to clean-code...@googlegroups.com
I suspected as much. Having said that I'm not really sure the "database" is not also an external system so I still feel like the name gateway can apply just as well to them.

Andreas Schaefer

unread,
Sep 11, 2013, 6:25:20 AM9/11/13
to clean-code...@googlegroups.com
Thank you for your thoughts and links on this topic!
I'm with you, tending to always use 'gateway' as the name, because it implies more openness and flexibilty.

Given the situation that you first used a local database and at some point in the future switched to a cloud storage, then it'd be kind of awkward if you had initially named it 'repository'.

Frederik Krautwald

unread,
Nov 18, 2014, 4:18:10 AM11/18/14
to clean-code...@googlegroups.com
Name giving can easily become a heated debate as we are talking semantics. If you really look at what the proposed gateway is, you’ll find that it is actually “just” an adapter interface for the data side, using the term data side from the ports and adapter pattern by Alistair Cockburn, which Uncle Bob’s clean architecture seem to adhere to. The data side gives access to data, so we get that the gateway is really a data access adapter interface. Whether you find that gateway is a good term to describe this interface, I’ll leave entirely up to you. To me, a gateway indicates something that can be opened and closed by, well, a gate. And I suspect UncleBob to have chosen this word by inspiration of the word port in the ports and adapters pattern, though that shall remain complete speculation. However, UncleBob’s gateway is not a port in the ports and adapters pattern. It is, as mentioned, an adapter interface.

On a side note, having defined an adapter interface as the gateway, does not guarantee that it works the intended way. For example, a gateway might have some get-me-this-entity-named-bla-bla-method defined, but not every technology that a gateway implementation / adapter “wraps” might be able to actually provide entity data by those means.

Summing up, in my world, gateway doesn’t say as much as data access adapter, or repository, for that matter. Take a look at these below, and consider which names would tell an unknowing more about what they really are.

UserGateway
UserRepository
UserDataAccessAdapter

In the end, it’s all about semantics, and Clean Code is all about conveying meaning of code.

Frederik Krautwald

unread,
Nov 18, 2014, 5:51:24 AM11/18/14
to clean-code...@googlegroups.com
In addendum, UncleBob could, of course, have adapted (no pun intended) the gateway name from Fowler’s Gateway pattern. In this context, it is worth emphasizing what Fowler says about this pattern, namely that a good strategy is to build the gateway in terms of more than one object  an obvious form is to use two objects: a back-end and a front-end, where the back-end acts as a minimal overlay to the external resource and doesn’t simplify the resource’s API at all. The front-end then transforms the awkward API into a more convenient one for the application to use. However, if the external service is simple, one class can handle the adaptation. The more I think about it, this might be exactly what dear UncleBob is referring to.
Reply all
Reply to author
Forward
0 new messages