Merge pull request #1472 from ravening/command

#1324 Use interfaces in command pattern
This commit is contained in:
Ilkka Seppälä 2020-08-04 17:47:32 +03:00 committed by GitHub
commit 97285d3724
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 23 deletions

View File

@ -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;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 75 KiB

View File

@ -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
Goblin --|> Target
InvisibilitySpell ..|> Command
ShrinkSpell ..|> Command
@enduml

View File

@ -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();
}

View File

@ -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;

View File

@ -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;