Command pattern
This commit is contained in:
21
design-pattern/src/Command/StringPrintCommand.java
Normal file
21
design-pattern/src/Command/StringPrintCommand.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package Command;
|
||||
|
||||
public class StringPrintCommand implements Command{
|
||||
|
||||
private final String string;
|
||||
|
||||
public StringPrintCommand(String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
System.out.println(this.string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Command o) {
|
||||
return this.string.length() - ((StringPrintCommand) o).string.length();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user