未验证 提交 97285d37 编写于 作者: I Ilkka Seppälä 提交者: GitHub

Merge pull request #1472 from ravening/command

#1324 Use interfaces in command pattern
......@@ -75,19 +75,18 @@ public class Wizard {
Next we present the spell hierarchy.
```java
public abstract class Command {
public interface Command {
public abstract void execute(Target target);
void execute(Target target);
public abstract void undo();
void undo();
public abstract void redo();
void redo();
@Override
public abstract String toString();
String toString();
}
public class InvisibilitySpell extends Command {
public class InvisibilitySpell implements Command {
private Target target;
......@@ -117,7 +116,7 @@ public class InvisibilitySpell extends Command {
}
}
public class ShrinkSpell extends Command {
public class ShrinkSpell implements Command {
private Size oldSize;
private Target target;
......
command/etc/command.png

27.0 KB | W: | H:

command/etc/command.png

75.3 KB | W: | H:

command/etc/command.png
command/etc/command.png
command/etc/command.png
command/etc/command.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -4,7 +4,7 @@ package com.iluwatar.command {
+ App()
+ main(args : String[]) {static}
}
abstract class Command {
interface Command {
+ Command()
+ execute(Target) {abstract}
+ redo() {abstract}
......@@ -77,7 +77,7 @@ ShrinkSpell --> "-oldSize" Size
InvisibilitySpell --> "-target" Target
ShrinkSpell --> "-target" Target
Target --> "-visibility" Visibility
Goblin --|> Target
InvisibilitySpell --|> Command
ShrinkSpell --|> Command
@enduml
\ No newline at end of file
Goblin --|> Target
InvisibilitySpell ..|> Command
ShrinkSpell ..|> Command
@enduml
......@@ -26,15 +26,12 @@ package com.iluwatar.command;
/**
* Interface for Commands.
*/
public abstract class Command {
public interface Command {
void execute(Target target);
public abstract void execute(Target target);
void undo();
public abstract void undo();
public abstract void redo();
@Override
public abstract String toString();
void redo();
String toString();
}
......@@ -26,7 +26,7 @@ package com.iluwatar.command;
/**
* InvisibilitySpell is a concrete command.
*/
public class InvisibilitySpell extends Command {
public class InvisibilitySpell implements Command {
private Target target;
......
......@@ -26,7 +26,7 @@ package com.iluwatar.command;
/**
* ShrinkSpell is a concrete command.
*/
public class ShrinkSpell extends Command {
public class ShrinkSpell implements Command {
private Size oldSize;
private Target target;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册