diff --git a/bridge-pattern/pom.xml b/bridge-pattern/pom.xml new file mode 100644 index 0000000..28d09b4 --- /dev/null +++ b/bridge-pattern/pom.xml @@ -0,0 +1,41 @@ + + 4.0.0 + bridge-pattern + bridge-pattern + 0.0.1-SNAPSHOT + + + ${java.version} + ${java.version} + 1.8 + 5.4.2 + + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + + maven-unit-test + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.0 + + + + + diff --git a/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/Controller.java b/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/Controller.java new file mode 100644 index 0000000..401bf64 --- /dev/null +++ b/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/Controller.java @@ -0,0 +1,9 @@ +package com.dotterbear.bridge.pattern; + +public interface Controller { + + public void joystickMove(String direction); + + public void pressHome(); + +} \ No newline at end of file diff --git a/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/ControllerFunction.java b/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/ControllerFunction.java new file mode 100644 index 0000000..f32c4fa --- /dev/null +++ b/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/ControllerFunction.java @@ -0,0 +1,9 @@ +package com.dotterbear.bridge.pattern; + +public interface ControllerFunction { + + public void joystickMove(String direction); + + public void pressHome(); + +} \ No newline at end of file diff --git a/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/PS4Controller.java b/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/PS4Controller.java new file mode 100644 index 0000000..acedea3 --- /dev/null +++ b/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/PS4Controller.java @@ -0,0 +1,21 @@ +package com.dotterbear.bridge.pattern; + +public class PS4Controller implements Controller { + + private ControllerFunction controllerFunction; + + public PS4Controller(ControllerFunction controllerFunction) { + this.controllerFunction = controllerFunction; + } + + @Override + public void joystickMove(String direction) { + controllerFunction.joystickMove(direction); + } + + @Override + public void pressHome() { + controllerFunction.pressHome(); + } + +} \ No newline at end of file diff --git a/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/PS4Function.java b/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/PS4Function.java new file mode 100644 index 0000000..837bb03 --- /dev/null +++ b/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/PS4Function.java @@ -0,0 +1,15 @@ +package com.dotterbear.bridge.pattern; + +public class PS4Function implements ControllerFunction { + + @Override + public void joystickMove(String direction) { + System.out.println("move " + direction); + } + + @Override + public void pressHome() { + System.out.println("show PS4 home menu"); + } + +} \ No newline at end of file diff --git a/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/SteamFunction.java b/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/SteamFunction.java new file mode 100644 index 0000000..41e5059 --- /dev/null +++ b/bridge-pattern/src/main/java/com/dotterbear/bridge/pattern/SteamFunction.java @@ -0,0 +1,15 @@ +package com.dotterbear.bridge.pattern; + +public class SteamFunction implements ControllerFunction { + + @Override + public void joystickMove(String direction) { + System.out.println("pressed " + direction); + } + + @Override + public void pressHome() { + System.out.println("unsupported button"); + } + +} \ No newline at end of file diff --git a/bridge-pattern/src/test/java/com/dotterbear/bridge/pattern/BridgePatternTest.java b/bridge-pattern/src/test/java/com/dotterbear/bridge/pattern/BridgePatternTest.java new file mode 100644 index 0000000..250be2e --- /dev/null +++ b/bridge-pattern/src/test/java/com/dotterbear/bridge/pattern/BridgePatternTest.java @@ -0,0 +1,21 @@ +package com.dotterbear.bridge.pattern; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +public class BridgePatternTest { + + @Test + public void test() { + Controller ps4ControllerWithPS4 = new PS4Controller(new PS4Function()); + Controller ps4ControllerWithSteam = new PS4Controller(new SteamFunction()); + System.out.println("move joystick up"); + ps4ControllerWithPS4.joystickMove("up"); + ps4ControllerWithSteam.joystickMove("up"); + System.out.println("press ps button"); + ps4ControllerWithPS4.pressHome(); + ps4ControllerWithSteam.pressHome(); + } + +} \ No newline at end of file