I want to build a Register class for a website. Here are my use cases —
- User will provide email id & password for registration
- If email id already exist then Register class will send an error message that this email already exist in our system
- If email doesn’t exist in our syetem then Register class will send an activation email in user email id and show message to user that — one activation email already sent to his/ser email
Here is the design that I thought about
Interface IRegister
{
string RegisterUser(string email, string password);
}
public class Register:IRegister
{
public string RegisterUser(string email, string password)
{
//Call IsUserExist and SentActivationEmail method internally
}
private bool IsUserExist()
{
}
private void SendActivationEmail()
{
}
}
I don’t want to mention IsUserExist and SendActivationEmail method in IRegister so that it remains simple. Now how I can enforce a developer who will implement the Register class that he/she should use IsUserExist and SendActivationEmail method and do all operations as mentioned in use case. And does this design violate SRP principle?
If you want to enforce that developers use those methods then you should be declaring an abstract class with protected abstract methods rather than an interface. Then the definition enforces the methods, but the developer is free to implement them however they need.
That being said, to keep with the SRP principle I would pull the email part of it out into a dependent IActivationEmailer interface. Emailing and registering are really two different actions and should be kept separate.