June 2018
Intermediate to advanced
280 pages
7h 46m
English
The following code shows how a simple print ASCII text can be enhanced to print the hex equivalent string for the input, besides the actual text:
package gof.structural.decorator;import java.util.stream.Collectors;publicclass Main{ publicstaticvoid main (String[] args) throws java.lang.Exception { final String text = "text"; final PrintText object = new PrintAsciiText(); final PrintText printer = new PrintTextHexDecorator(object); object.print(text); printer.print(text); }}interface PrintText { publicvoid print(String text);}PrintText is the component interface:class PrintAsciiText implements PrintText { publicvoid print(String text) { System.out.println("Print ASCII: " + text); }}
PrintASCIIText is the component to be decorated. ...
Read now
Unlock full access