Repository: iluwatar/java-design-patterns
Issue: Inheritence in Command pattern
Labels: epic: pattern
type: enhancement
info: good first issue

I see that the `Command` is a class instead of `interface` and all the target actions extends this class.
Typically `Command` should be interface and the targets should implement the interface.
So should we rewrite the command pattern to implement interface rather than using inheritance?

Issue comments:
Yes, I agree that would be the typical scenario and in this case it would suit the example fine.

@ravening let's leave the issue open if somebody wants to implement it
@iluwatar I can work on it if you are ok with it.
Should I write separate classes/interfaces or rewrite the existing abstract classes with interfaces?
I think you can modify the existing

Pull request review comments:

Patch that resolved the issue:
diff --git a/command/README.md b/command/README.md
index fc0a11d9ffe8..b763cf4dd1c5 100644
--- a/command/README.md
+++ b/command/README.md
@@ -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;
diff --git a/command/etc/command.urm.puml b/command/etc/command.urm.puml
index a8b773418ee3..c9c172226fa3 100644
--- a/command/etc/command.urm.puml
+++ b/command/etc/command.urm.puml
@@ -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
diff --git a/command/src/main/java/com/iluwatar/command/Command.java b/command/src/main/java/com/iluwatar/command/Command.java
index 85deff74efd8..83010f1604d0 100644
--- a/command/src/main/java/com/iluwatar/command/Command.java
+++ b/command/src/main/java/com/iluwatar/command/Command.java
@@ -26,15 +26,12 @@
 /**
  * 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();
 }
diff --git a/command/src/main/java/com/iluwatar/command/InvisibilitySpell.java b/command/src/main/java/com/iluwatar/command/InvisibilitySpell.java
index 3e0f7bbf4fef..33e053cc2e3b 100644
--- a/command/src/main/java/com/iluwatar/command/InvisibilitySpell.java
+++ b/command/src/main/java/com/iluwatar/command/InvisibilitySpell.java
@@ -26,7 +26,7 @@
 /**
  * InvisibilitySpell is a concrete command.
  */
-public class InvisibilitySpell extends Command {
+public class InvisibilitySpell implements Command {
 
   private Target target;
 
diff --git a/command/src/main/java/com/iluwatar/command/ShrinkSpell.java b/command/src/main/java/com/iluwatar/command/ShrinkSpell.java
index 87497bb7bed8..3f21fc7c1fc7 100644
--- a/command/src/main/java/com/iluwatar/command/ShrinkSpell.java
+++ b/command/src/main/java/com/iluwatar/command/ShrinkSpell.java
@@ -26,7 +26,7 @@
 /**
  * ShrinkSpell is a concrete command.
  */
-public class ShrinkSpell extends Command {
+public class ShrinkSpell implements Command {
 
   private Size oldSize;
   private Target target;


Test patch: