Created
April 14, 2015 07:17
-
-
Save bgeihsgt/ce41282a5cb57c6c8577 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserSignup | |
{ | |
private IEmailValidator emailValidator; | |
public UserSignup(IEmailValidator emailValidator) | |
{ | |
this.emailValidator = emailValidator; | |
} | |
public void Signup(string emailAddress, string password) | |
{ | |
emailValidator.Validate(emailAddress); | |
// Do your signup magics | |
} | |
} | |
public interface IEmailValidator | |
{ | |
void Validate(string emailAddress); | |
} | |
public class EmailValidator : IEmailValidator | |
{ | |
public void Validate(string emailAddress) | |
{ | |
if (!IsValid(emailAddress)) | |
throw new InvalidEmailAddressException(emailAddress); | |
} | |
private static bool IsValid(string emailAddress) | |
{ | |
// do your fancy string magics | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment