You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: component/README.md
+11-20Lines changed: 11 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -18,36 +18,27 @@ tag:
18
18
19
19
The Component design pattern aims to organize code into reusable, interchangeable components, promoting flexibility and ease of maintenance in game development by allowing entities to be configured with varying behaviors.
> Suppose your video game consists of a graphics component and a sound component. Including the methods and attributes of both of these features in a single java class can be problematic due to many reasons. Firstly, the graphics and sound code can create an extremely long java class which can be hard to maintain. Furthermore, graphics components may be written and implemented by a separate team as to the sound contents. If both parties work simultaneously on the same java class, this may cause conflicts and major delay. Using the component design pattern, the development team is able to create individual component classes for graphics and sound whilst providing the domain/object the reach to both of these attributes.
23
+
Real-world example
27
24
25
+
> Imagine your video game has a graphics component and a sound component. Combining the methods and attributes of both features into a single Java class can lead to several issues. Firstly, the resulting class could become very lengthy and difficult to maintain. Additionally, the graphics and sound components might be developed by separate teams. If both teams work on the same Java class simultaneously, it could cause conflicts and significant delays. By using the Component design pattern, the development team can create separate component classes for graphics and sound, while still allowing the main game object to access both sets of attributes.
28
26
29
27
In plain words
30
-
> The component design pattern provides a single attribute to be accessible by numerous objects without requiring the existence of a relationship between the objects themselves.
31
28
32
-
Key drawback
33
-
> With the implementation of the component design pattern, it can be very difficult to create a relationship between components. For example, suppose we require the sound component to be aware of the current animation in order create a certain sound based upon the animation; this can be quite tricky as the component design pattern makes components 'unaware' of other components' existence due to its decoupling nature.
29
+
> The component design pattern provides a single attribute to be accessible by numerous objects without requiring the existence of a relationship between the objects themselves.
34
30
35
31
**Programmatic Example**
36
32
37
-
The App class creates a demonstration of the use of the component pattern by creating two different objects which inherit a small collection of individual components that are modifiable.
33
+
The `App` class creates a demonstration of the use of the component pattern by creating two different objects which inherit a small collection of individual components that are modifiable.
38
34
39
35
```java
40
36
publicfinalclassApp {
41
-
/**
42
-
* Program entry point.
43
-
*
44
-
* @param args args command line args.
45
-
*/
37
+
46
38
publicstaticvoidmain(String[] args) {
47
39
finalvar player =GameObject.createPlayer();
48
40
finalvar npc =GameObject.createNpc();
49
41
50
-
51
42
LOGGER.info("Player Update:");
52
43
player.update(KeyEvent.KEY_LOCATION_LEFT);
53
44
LOGGER.info("NPC Update:");
@@ -56,7 +47,7 @@ public final class App {
56
47
}
57
48
```
58
49
59
-
Much of the program exists within the GameObject class, within this class, the player and NPC object create methods are set up. Additionally, this class also consists of the method calls used to update/alter information of the object's components.
50
+
Much of the program exists within the `GameObject` class, within this class, the player and NPC object create methods are set up. Additionally, this class also consists of the method calls used to update/alter information of the object's components.
60
51
61
52
```java
62
53
publicclassGameObject {
@@ -105,7 +96,7 @@ public class GameObject {
105
96
}
106
97
```
107
98
108
-
Upon opening the component package, the collection of components are revealed. These components provide the interface for objects to inherit these domains. The PlayerInputComponent class shown below updates the object's velocity characteristic based on user's key event input.
99
+
Upon opening the component package, the collection of components are revealed. These components provide the interface for objects to inherit these domains. The `PlayerInputComponent` class shown below updates the object's velocity characteristic based on user's key event input.
0 commit comments