Skip to content

Instantly share code, notes, and snippets.

@0xvoila 0xvoila/uml3.java
Created May 7, 2017

Embed
What would you like to do?
public Class MailConfiguration{
public static String userName;
public static String password;
public static EmailServiceProvider emailService;
}
public Class MailInit{
public void initialConfiguration(String userName, String password, String emailService ){
MailConfiguration.userName = userName;
MailConfiguration.password = password;
if(emailService == "google"){
MailConfiguration.emailService = Class.forName('GmailEmailProvider').getInstance();
}
else{
MailConfiguration.emailService = Class.forName('YahooEmailProvider').getInstance();
}
}
}
public Interface EmailServiceProvider{
public Connection connect(String userName, String password);
public void sendEmail(String recipient, String subject, String messageBody);
public String receiveEmail();
}
public Class GoogleEmailProvider implements EmailServiceProvider{
private GMailLowLevelConnection gmailLowLevelConnection;
@Override
public connect(String userName, String password){
GMailLowLevelClass gmailLowLevelClassObject = new GMailLowLevelClass();
this.gmailLowLevelConnection = gmailLowLevelClassObject.connect(String userName, String password);
}
@Override
public sendEmail(String recipient, String subject, String messageBody){
this.gmailLowLevelConnection.send(recipient, subject , messageBody );
}
@Override
public String receiveEmail(){
return this.gmailLowLevelConnection.receiveEmail();
}
}
public Class YahooEmailService implements EmailService{
private YahooMailLowLevelConnection yahooLowLevelConnection;
@Override
public connect(String userName, String password){
YahooLowLevelClass yahooLowLevelClassObject = new YahooLowLevelClass();
this.yahooLowLevelConnection = yahooLowLevelClassObject.connect(String userName, String password);
}
@Override
public sendEmail(String recipient, String subject, String messageBody){
this.yahooLowLevelConnection.send(recipient, subject , messageBody );
}
@Override
public String receiveEmail(){
return this.yahooLowLevelConnection.receiveEmail();
}
}
public Class Mail{
public void sendEmail(String recipient, String subject, String messageBody){
MailConfiguration.emailService.connect(MailConfiguration.userName, MailConfiguration.password);
MailConfiguration.emailService.send(recipient, subject,messageBody);
}
public String receiveEmail(){
MailConfiguration.emailService.connect(MailConfiguration.userName, MailConfiguration.password);
return MailConfiguration.emailService.receive();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.