From 68a5df1cc9ee48f151b9aba6c52307e535c12d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ilkka=20Sepp=C3=A4l=C3=A4?= Date: Wed, 29 Dec 2021 19:05:16 +0200 Subject: [PATCH] delete unwanted files --- component/README.md | 25 ---- component/component.iml | 31 ---- component/etc/component.urm.puml | 2 - component/pom.xml | 42 ------ .../main/java/com/iluwatar/component/App.java | 56 ------- .../component/BjornGraphicsComponent.java | 25 ---- .../component/BjornInputComponent.java | 22 --- .../component/BjornPhysicsComponent.java | 27 ---- .../com/iluwatar/component/Component.java | 9 -- .../com/iluwatar/component/GameObject.java | 87 ----------- .../iluwatar/component/GraphicsComponent.java | 8 - .../iluwatar/component/InputComponent.java | 7 - .../iluwatar/component/PhysicsComponent.java | 7 - component/src/main/java/module-info.java | 26 ---- .../java/com/iluwatar/component/AppTest.java | 37 ----- .../com/iluwatar/component/UpdateTest.java | 138 ------------------ 16 files changed, 549 deletions(-) delete mode 100644 component/README.md delete mode 100644 component/component.iml delete mode 100644 component/etc/component.urm.puml delete mode 100644 component/pom.xml delete mode 100644 component/src/main/java/com/iluwatar/component/App.java delete mode 100644 component/src/main/java/com/iluwatar/component/BjornGraphicsComponent.java delete mode 100644 component/src/main/java/com/iluwatar/component/BjornInputComponent.java delete mode 100644 component/src/main/java/com/iluwatar/component/BjornPhysicsComponent.java delete mode 100644 component/src/main/java/com/iluwatar/component/Component.java delete mode 100644 component/src/main/java/com/iluwatar/component/GameObject.java delete mode 100644 component/src/main/java/com/iluwatar/component/GraphicsComponent.java delete mode 100644 component/src/main/java/com/iluwatar/component/InputComponent.java delete mode 100644 component/src/main/java/com/iluwatar/component/PhysicsComponent.java delete mode 100644 component/src/main/java/module-info.java delete mode 100644 component/src/test/java/com/iluwatar/component/AppTest.java delete mode 100644 component/src/test/java/com/iluwatar/component/UpdateTest.java diff --git a/component/README.md b/component/README.md deleted file mode 100644 index edd5bfc2c..000000000 --- a/component/README.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -layout: pattern -title: Component -folder: component -permalink: /patterns/component/ -categories: Behavioral -tags: - - Java - - Game Programming - - Decoupling ---- - -## Intent - -> Allow a single entity to span multiple domains without coupling the domains to each other. - - -## Applicability -1.You want to keep decoupled from each other in a class which contains multiple domains. -2.A class is too big and massive. - - -## Reference - -* [http://gameprogrammingpatterns.com/component.html] diff --git a/component/component.iml b/component/component.iml deleted file mode 100644 index f7c05039f..000000000 --- a/component/component.iml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/component/etc/component.urm.puml b/component/etc/component.urm.puml deleted file mode 100644 index 02af47ddf..000000000 --- a/component/etc/component.urm.puml +++ /dev/null @@ -1,2 +0,0 @@ -@startuml -@enduml \ No newline at end of file diff --git a/component/pom.xml b/component/pom.xml deleted file mode 100644 index 399f1d152..000000000 --- a/component/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - java-design-patterns - com.iluwatar - 1.23.0-SNAPSHOT - - 4.0.0 - - component - - - org.junit.jupiter - junit-jupiter-engine - test - - - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - - - - com.iluwatar.component.App - - - - - - - - - - diff --git a/component/src/main/java/com/iluwatar/component/App.java b/component/src/main/java/com/iluwatar/component/App.java deleted file mode 100644 index 1df2cd50f..000000000 --- a/component/src/main/java/com/iluwatar/component/App.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * The MIT License - * Copyright © 2014-2019 Ilkka Seppälä - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.iluwatar.component; - -import java.util.ArrayList; -/** - * Object-oriented to a certain extent can solve many problems of code reuse and data reuse, - * but it also has great defects: - * 1.the coupling of data organization is very strong. - * 2.Interface logic is difficult to reuse and hot plug. - * - * The component pattern solves the defects of object orientation and process orientation and - * is widely used in game clients - * - * A component is a part of one object. We can consider that a object contains multiple - * components, in another way, multiple components can construct a object. - * Here is a demo using component pattern to solve a game-like problem. - * A person named Bjorn who has three components: input;physics;graphics - * These three component with a common game object can construct our protagonist:Bjorn, also can - * construct other objects like dog or cat if you want to write a real game. - */ - -public class App { - /** - * Launcher for this demo design pattern - */ - public static void main(String[] args) { - var arrayList = new ArrayList(); - arrayList.add(new BjornInputComponent()); - arrayList.add(new BjornPhysicsComponent()); - arrayList.add(new BjornGraphicsComponent()); - var gameObject = new GameObject(arrayList); - gameObject.update(); - } -} diff --git a/component/src/main/java/com/iluwatar/component/BjornGraphicsComponent.java b/component/src/main/java/com/iluwatar/component/BjornGraphicsComponent.java deleted file mode 100644 index 912b3190c..000000000 --- a/component/src/main/java/com/iluwatar/component/BjornGraphicsComponent.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.iluwatar.component; - -import static org.slf4j.LoggerFactory.getLogger; - -import org.slf4j.Logger; - -/** - * BjornGraphicsComponent is a class for our main game star - * This class creat a Graphics component for Bjorn. - */ - -public class BjornGraphicsComponent implements GraphicsComponent { - private static final Logger LOGGER = getLogger(BjornGraphicsComponent.class); - - /** - * This method is a logger for Bjorn when happens a Graphics update. - * In real scenario, there will be code for Graphics Update. - * - * @param gameObject is a object in the game, here it is Bjorn - */ - @Override - public void update(GameObject gameObject) { - LOGGER.info("positive:" + gameObject.getPositionOFx() + "," + gameObject.getPositionOFy()); - } -} diff --git a/component/src/main/java/com/iluwatar/component/BjornInputComponent.java b/component/src/main/java/com/iluwatar/component/BjornInputComponent.java deleted file mode 100644 index 585f30715..000000000 --- a/component/src/main/java/com/iluwatar/component/BjornInputComponent.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.iluwatar.component; - -/** - * BjornInputComponent is a class for our main game star - * This class creat a Input component for Bjorn. - */ - -public class BjornInputComponent implements InputComponent { - - /** - * This method is a logger for Bjorn when happens a Input update. - * In real scenario, there will be code for dealing with IO. - * - * @param gameObject is a object in the game, here it is Bjorn - */ - - @Override - public void update(GameObject gameObject) { - gameObject.setPositionOFx(gameObject.getPositionOFx() + gameObject.getVelocity()); - gameObject.setPositionOFy(gameObject.getPositionOFy() + gameObject.getVelocity()); - } -} diff --git a/component/src/main/java/com/iluwatar/component/BjornPhysicsComponent.java b/component/src/main/java/com/iluwatar/component/BjornPhysicsComponent.java deleted file mode 100644 index 6c3db04dc..000000000 --- a/component/src/main/java/com/iluwatar/component/BjornPhysicsComponent.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.iluwatar.component; - -import static org.slf4j.LoggerFactory.getLogger; - -import org.slf4j.Logger; - -/** - * BjornPhysicsComponent is a class for our main game star - * This class creat a Physics component for Bjorn. - */ -public class BjornPhysicsComponent implements PhysicsComponent{ - - private static final Logger LOGGER = getLogger(BjornPhysicsComponent.class); - - /** - * This method is a logger for Bjorn when happens a Physics update. - * In real scenario, there will be code for Physics Update. - * - * @param gameObject is a object in the game, here it is Bjorn - */ - @Override - public void update(GameObject gameObject) { - if(gameObject.getPositionOFx() == gameObject.getPositionOFy()){ - LOGGER.info("Your position is pretty good, keep it!"); - } - } -} diff --git a/component/src/main/java/com/iluwatar/component/Component.java b/component/src/main/java/com/iluwatar/component/Component.java deleted file mode 100644 index 1771b3b88..000000000 --- a/component/src/main/java/com/iluwatar/component/Component.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.iluwatar.component; - - -/** - * Component is an interface for all component. - */ - -public interface Component { void update(GameObject gameObject); -} diff --git a/component/src/main/java/com/iluwatar/component/GameObject.java b/component/src/main/java/com/iluwatar/component/GameObject.java deleted file mode 100644 index 78844e6ba..000000000 --- a/component/src/main/java/com/iluwatar/component/GameObject.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.iluwatar.component; - -import java.util.ArrayList; - -/** - * GameObject is a class for all object in the game. - * It was constructed by a collection of component. - */ - -public class GameObject { - private int velocity; - private int positionOFx; - private int positionOFy; - ArrayList componentArrayList; - - /** - * Constructor for GameObject - * @param componentArrayList is the list of this object contains - */ - - public GameObject(ArrayList componentArrayList){ - this.componentArrayList=new ArrayList<>(); - this.componentArrayList.addAll(componentArrayList); - } - - /** - * setter for velocity - * @param velocity is the velocity of this object - */ - - public void setVelocity(int velocity) { - this.velocity = velocity; - } - - /** - * getter for velocity - */ - - public int getVelocity() { - return velocity; - } - - /** - * setter for PositionOFx - * @param positionOFx is the PositionOFx of this object - */ - - public void setPositionOFx(int positionOFx) { - this.positionOFx = positionOFx; - } - - - /** - * getter for PositionOFx - */ - - public int getPositionOFx() { - return positionOFx; - } - - /** - * setter for PositionOFy - * @param positionOFy is the PositionOFy of this object - */ - - public void setPositionOFy(int positionOFy) { - this.positionOFy = positionOFy; - } - - /** - * getter for PositionOFy - */ - - public int getPositionOFy() { - return positionOFy; - } - - /** - * update for this object's components. - */ - - public void update(){ - for (Component component : componentArrayList) { - component.update(this); - } - } -} diff --git a/component/src/main/java/com/iluwatar/component/GraphicsComponent.java b/component/src/main/java/com/iluwatar/component/GraphicsComponent.java deleted file mode 100644 index 4e6a58ce0..000000000 --- a/component/src/main/java/com/iluwatar/component/GraphicsComponent.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.iluwatar.component; - -/** - * GraphicsComponent is an interface for Graphics function - */ - -public interface GraphicsComponent extends Component { void update(GameObject gameObject); -} diff --git a/component/src/main/java/com/iluwatar/component/InputComponent.java b/component/src/main/java/com/iluwatar/component/InputComponent.java deleted file mode 100644 index 4f020b265..000000000 --- a/component/src/main/java/com/iluwatar/component/InputComponent.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.iluwatar.component; - -/** - * InputComponent is an interface for Input function - */ -public interface InputComponent extends Component { void update(GameObject gameObject); -} diff --git a/component/src/main/java/com/iluwatar/component/PhysicsComponent.java b/component/src/main/java/com/iluwatar/component/PhysicsComponent.java deleted file mode 100644 index ec6facc5a..000000000 --- a/component/src/main/java/com/iluwatar/component/PhysicsComponent.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.iluwatar.component; - -/** - * PhysicsComponent is an interface for Physics function - */ -public interface PhysicsComponent extends Component { void update(GameObject gameObject); -} diff --git a/component/src/main/java/module-info.java b/component/src/main/java/module-info.java deleted file mode 100644 index b7432970f..000000000 --- a/component/src/main/java/module-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * The MIT License - * Copyright © 2014-2019 Ilkka Seppälä - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -module com.iluwatar.component { - requires org.slf4j; -} diff --git a/component/src/test/java/com/iluwatar/component/AppTest.java b/component/src/test/java/com/iluwatar/component/AppTest.java deleted file mode 100644 index 04f86d81f..000000000 --- a/component/src/test/java/com/iluwatar/component/AppTest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * The MIT License - * Copyright © 2014-2019 Ilkka Seppälä - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package com.iluwatar.component; - -import org.junit.jupiter.api.Test; -/** - * Tests that Component example runs without errors. - */ -public class AppTest { - /** - * test for the design pattern runnable. - */ - @Test - public void test() { - App.main(new String[]{}); - } -} diff --git a/component/src/test/java/com/iluwatar/component/UpdateTest.java b/component/src/test/java/com/iluwatar/component/UpdateTest.java deleted file mode 100644 index 362ae9b57..000000000 --- a/component/src/test/java/com/iluwatar/component/UpdateTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * The MIT License - * Copyright © 2014-2019 Ilkka Seppälä - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package com.iluwatar.component; - -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; - -import static junit.framework.TestCase.assertEquals; - -/** - * Tests that Component example runs without errors. - */ - -public class UpdateTest { - /** - * test for the update for the input component of the object - */ - @Test - public void inputUpdateTest() { - var arrayList = new ArrayList(); - arrayList.add(new BjornInputComponent()); - var gameObject = new GameObject(arrayList); - gameObject.setPositionOFy(12); - gameObject.setPositionOFx(13); - gameObject.setVelocity(1); - gameObject.update(); - assertEquals(14, gameObject.getPositionOFx()); - assertEquals(13,gameObject.getPositionOFy()); - } - /** - * test for the update for the Physics component of the object - */ - @Test - public void physicsUpdateTest() { - var arrayList = new ArrayList(); - arrayList.add(new BjornPhysicsComponent()); - arrayList.add(new BjornGraphicsComponent()); - var gameObject = new GameObject(arrayList); - gameObject.setPositionOFy(13); - gameObject.setPositionOFx(12); - gameObject.setVelocity(1); - gameObject.update(); - assertEquals(13, gameObject.getPositionOFx()); - assertEquals(14,gameObject.getPositionOFy()); - } - /** - * test for the update for the Graphics component of the object - */ - @Test - public void graphicsUpdateTest() { - var arrayList = new ArrayList(); - arrayList.add(new BjornInputComponent()); - arrayList.add(new BjornPhysicsComponent()); - arrayList.add(new BjornGraphicsComponent()); - var gameObject = new GameObject(arrayList); - gameObject.setPositionOFy(1); - gameObject.setPositionOFx(1); - gameObject.setVelocity(1); - gameObject.update(); - assertEquals(2, gameObject.getPositionOFx()); - assertEquals(2,gameObject.getPositionOFy()); - } - /** - * test for the setPositionOFx - */ - @Test - public void setPositionOFxTest(){ - var gameObject = new GameObject(null); - gameObject.setPositionOFx(1); - assertEquals(1,gameObject.getPositionOFx()); - } - /** - * test for the getPositionOFx - */ - @Test - public void getPositionOFxTest(){ - var gameObject = new GameObject(null); - gameObject.setPositionOFx(1); - assertEquals(1,gameObject.getPositionOFx()); - } - /** - * test for the setPositionOFy - */ - @Test - public void setPositionOFyTest(){ - var gameObject = new GameObject(null); - gameObject.setPositionOFy(1); - assertEquals(1,gameObject.getPositionOFy()); - } - /** - * test for the getPositionOFy - */ - @Test - public void getPositionOFyTest(){ - var gameObject = new GameObject(null); - gameObject.setPositionOFy(1); - assertEquals(1,gameObject.getPositionOFy()); - } - /** - * test for the setVelocity - */ - @Test - public void setVelocityTest(){ - var gameObject = new GameObject(null); - gameObject.setVelocity(1); - assertEquals(1,gameObject.getVelocity()); - } - /** - * test for the getVelocity - */ - @Test - public void getVelocityTest(){ - var gameObject = new GameObject(null); - gameObject.setVelocity(1); - assertEquals(1,gameObject.getVelocity()); - } -}