I'm unsure about several things:

  • I have a class that implements a NotificationDispatcher interface. This class I named WhatsappNotificationDispatcher, another implementation goes by EmailNotificationDispatcher.

  • The Whatsapp message delivery itself is implemented by the API of an external service provider.

So now I have a class that both

[1] Implements a dispatch type (Whatsapp) [2] Implements a service provider for that type

And to make matters worse, all this is going on in my application layer. Because WhatsappNotificationDispatcher is an implementation of an API, but it's also a service.

Should I move implementation into the infrastructure layer always? And do I need to create an extra interface for WhatsappNotificationDispatcher, do implement a specific service provider API? It seems like madness.

1 Answer 1


If I understand well, your WhatsappNotificationDispatcher implements directly requests to an external service provider.

I tried to show this by in this diagram, where ResAPI is a proxy that helps to route general APU requests to external providers:

enter image description here

First of all this seems perfectly fine for me: your class implements an interface, and this requires to send requests to outside using an API.

Now I can't really imagine that you implement low level request making over http in your class with session management etc. This is why I added the proxy to handle this. This general purpose proxy would be in the infrastructure layer.

A better approach is to encapsulate the specific API itself, using the gateway pattern. The dispatcher level provides an application service and would remain in the application layer. The gateway would however be in a lower level (at same level than data access). This design would have the additional advantage of making your class SRP compliant.

However, if you would only use of the Whatsapp service provider API for the notification dispatcher, this additional separate gateway could be an unnecessary overhead. So you will have to decide depending on the full picture. In this case, intuitively I'd let the class in the application layer, but the opposite could be defended as well (sure you do'nt want the gateway after all?).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.