File tree Expand file tree Collapse file tree 1 file changed +39
-1
lines changed
Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -195,4 +195,42 @@ and functional interfaces to design API
195195 return color.getBlue();
196196 }
197197 }
198- ```
198+ ```
199+ 1. create complex DSL with hiding creation inside
200+ ```
201+ @Value
202+ @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
203+ public class Mailer {
204+ private static final Mailer EMPTY = new Mailer();
205+
206+ String from;
207+ String to;
208+
209+ private Mailer() {
210+ this.from = "";
211+ this.to = "";
212+ }
213+
214+ Mailer from(String from) {
215+ return new Mailer(StringUtils.defaultIfEmpty(from, ""), to);
216+ }
217+
218+ Mailer to(String to) {
219+ return new Mailer(from, StringUtils.defaultIfEmpty(to, ""));
220+ }
221+
222+ static void send(UnaryOperator<Mailer> block) {
223+ System.out.println(block.apply(EMPTY));
224+ }
225+ }
226+ ```
227+ and the example of usage:
228+ ```
229+ Mailer.send(
230+ mailer -> mailer.from("mtumilowicz01@gmail.com")
231+ .to("abc@o2.pl")
232+ )
233+ ```
234+ **note that in any point we don't have direct access to the object,
235+ we cannot create object manually and we cannot reuse it
236+ (there is NO Mailer object)**
You can’t perform that action at this time.
0 commit comments