Extracting notifications layer
What is the notifications layer? We can define it as an abstraction layer responsible for orchestrating user notifications. The responsibilities of this layer are as listed here:
- Deciding which communication channels to use for a given notification and a user
- Preparing notification payloads (email subjects and bodies, SMS contents, and so on)
- Interacting with delivery services (mailing servers, third-party APIs, and so on)
A notifications layer may be comprised of multiple abstractions or sub-layers. For example, we still can (and should) use Action Mailer for emails, but we need a higher-level entry-point abstraction, which would delegate the specific channel logic to lower abstractions.
As the first step toward a new abstraction, let’s refactor our Post::Publish
class using a simple object (or class) extraction technique.
Ad hoc abstraction
Let’s start by moving the #notify_subscribers
method implementation...