Skip to content

Commit 19c6548

Browse files
committed
docs: update component
1 parent a0d4729 commit 19c6548

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

component/README.md

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,27 @@ tag:
1818

1919
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.
2020

21-
![Intent](./etc/component.duplication.png "Component Design Pattern")
22-
2321
## Explanation
2422

25-
Real world example
26-
> 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
2724

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.
2826
2927
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.
3128

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.
3430
3531
**Programmatic Example**
3632

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.
3834

3935
```java
4036
public final class App {
41-
/**
42-
* Program entry point.
43-
*
44-
* @param args args command line args.
45-
*/
37+
4638
public static void main(String[] args) {
4739
final var player = GameObject.createPlayer();
4840
final var npc = GameObject.createNpc();
4941

50-
5142
LOGGER.info("Player Update:");
5243
player.update(KeyEvent.KEY_LOCATION_LEFT);
5344
LOGGER.info("NPC Update:");
@@ -56,7 +47,7 @@ public final class App {
5647
}
5748
```
5849

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.
6051

6152
```java
6253
public class GameObject {
@@ -105,7 +96,7 @@ public class GameObject {
10596
}
10697
```
10798

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.
109100

110101
```java
111102
public class PlayerInputComponent implements InputComponent {
@@ -139,7 +130,7 @@ public class PlayerInputComponent implements InputComponent {
139130

140131
## Class diagram
141132

142-
![UML](./etc/component.uml.png "The UML for Component Design Pattern")
133+
![Component](./etc/component.uml.png "Component")
143134

144135
## Applicability
145136

@@ -172,8 +163,8 @@ Trade-offs:
172163

173164
## Credits
174165

175-
* [Component Design Pattern] (https://gameprogrammingpatterns.com/component.html)
176-
* [Component pattern - game programming series - Tutemic] (https://www.youtube.com/watch?v=n92GBp2WMkg&ab_channel=Tutemic)
177166
* [Game Programming Patterns](https://amzn.to/4cDRWhV)
178-
* [Unity in Action: Multiplatform Game Development in C#](https://amzn.to/3THO6vw)
179167
* [Procedural Content Generation for Unity Game Development](https://amzn.to/3vBKCTp)
168+
* [Unity in Action: Multiplatform Game Development in C#](https://amzn.to/3THO6vw)
169+
* [Component (Game Programming Patterns)](https://gameprogrammingpatterns.com/component.html)
170+
* [Component pattern - game programming series (Tutemic)](https://www.youtube.com/watch?v=n92GBp2WMkg&ab_channel=Tutemic)
-295 KB
Binary file not shown.

0 commit comments

Comments
 (0)