I’m currently taking over a project that has a common pattern of interfaces like this:
public interface EmailService { void sendInvitationEmail(Payload payload); void sendNotificationEmailToAdmin(Payload payload); void sendPasswordResetEmailToUser(User user); void sendValidationEmailToNewUser(User user); }
Then the implementation gets injected with many different services and repositories to collect the necessary relations that are needed to have every piece of information. I feel like this could be an interface with a single method:
public interface EmailService { void sendEmail(String recipient, EmailContext context); }
But then I would often end up having multiple implementations injected into a single class that would send different types of emails, which also smells. Am I overthinking this? What’s the preferred way to go about this?