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: README.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -75,6 +75,10 @@ This pattern is useful if you have many objects. Even though a single object tak
75
75
76
76
* If you make Minecraft and have a million cubes in the scene. All cubes can share the same texture if you put all textures that belongs to each cube type (grass, stone, sand, etc) into a [texture atlas](https://en.wikipedia.org/wiki/Texture_atlas).
77
77
78
+
* If you make a strategy game, all infantry units share the same mesh, texture, maxHealth settings, etc. You only need to create one object with this data and then all infantry units can share that object. Each individual infantry unit only need to keep track of its own position and health.
79
+
80
+
* This is implemented in Unity as [sharedMesh](https://docs.unity3d.com/ScriptReference/MeshFilter-sharedMesh.html) and [sharedMaterial](https://docs.unity3d.com/ScriptReference/Renderer-sharedMaterial.html). If you make a change to a sharedMesh then all objects using that mesh will get a new mesh.
81
+
78
82
**Related patterns**
79
83
80
84
*[Type object](#12-type-object). The main difference is that in Type object you don't need to have the exact same data and you can also have behavior.
@@ -505,7 +509,7 @@ You have some class you want to add some behaviors to in a flexible way without
505
509
506
510
## 21. Factory
507
511
508
-
It can be useful to collect all methods on how to create new objects in their own class. This makes the code better organized. For each object you make you have to allocate some memory, and by creating all objects in a central area it makes it easier to monitor these allocations.
512
+
Collect all methods on how to create new objects in their own class. For each object you make you have to allocate some memory, and by creating all objects in a central area it makes it easier to monitor these allocations - especially if several team mambers are working on the code. The factory can also be responsible for the destruction of objects.
0 commit comments