Created
February 17, 2018 16:18
-
-
Save rakeshopensource/47ff319aba116de7843b5787fa3ed775 to your computer and use it in GitHub Desktop.
Loan Pattern using Java8
This file contains hidden or 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
import java.util.function.Consumer; | |
class MailBuilder { | |
private String from; | |
private String to; | |
private String subject; | |
private String body; | |
public MailBuilder from(final String fromAddress) { | |
this.from = fromAddress; | |
return this; | |
} | |
public MailBuilder to(final String toAddress) { | |
this.to=toAddress; | |
return this; | |
} | |
public MailBuilder subject(final String subject) { | |
this.subject=subject; | |
return this; | |
} | |
public MailBuilder body(final String message) { | |
this.body=message; | |
return this; | |
} | |
public static void send(final Consumer<MailBuilder> block) { | |
final MailBuilder mailer = new MailBuilder(); | |
block.accept(mailer); | |
System.out.println("Email Sent"); | |
} | |
} | |
public class LoanPattern { | |
public static void main(String[] args) { | |
MailBuilder.send(mailer -> | |
mailer.from("[email protected]") | |
.to("[email protected]") | |
.subject("Alert") | |
.body("Tasks Done...")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Loan design implementation using JAVA 8