Skip to content

Commit 78d8f8b

Browse files
committed
Added Facade pattern
1 parent 0024ff8 commit 78d8f8b

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

Assets/Patterns/21. Factory/Car Factory/car factory.unity

+43
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,49 @@ NavMeshSettings:
121121
debug:
122122
m_Flags: 0
123123
m_NavMeshData: {fileID: 0}
124+
--- !u!1 &158245195
125+
GameObject:
126+
m_ObjectHideFlags: 0
127+
m_CorrespondingSourceObject: {fileID: 0}
128+
m_PrefabInstance: {fileID: 0}
129+
m_PrefabAsset: {fileID: 0}
130+
serializedVersion: 6
131+
m_Component:
132+
- component: {fileID: 158245197}
133+
- component: {fileID: 158245196}
134+
m_Layer: 0
135+
m_Name: Controller
136+
m_TagString: Untagged
137+
m_Icon: {fileID: 0}
138+
m_NavMeshLayer: 0
139+
m_StaticEditorFlags: 0
140+
m_IsActive: 1
141+
--- !u!114 &158245196
142+
MonoBehaviour:
143+
m_ObjectHideFlags: 0
144+
m_CorrespondingSourceObject: {fileID: 0}
145+
m_PrefabInstance: {fileID: 0}
146+
m_PrefabAsset: {fileID: 0}
147+
m_GameObject: {fileID: 158245195}
148+
m_Enabled: 1
149+
m_EditorHideFlags: 0
150+
m_Script: {fileID: 11500000, guid: 276cbb15725a8d44a88585056b761f9a, type: 3}
151+
m_Name:
152+
m_EditorClassIdentifier:
153+
--- !u!4 &158245197
154+
Transform:
155+
m_ObjectHideFlags: 0
156+
m_CorrespondingSourceObject: {fileID: 0}
157+
m_PrefabInstance: {fileID: 0}
158+
m_PrefabAsset: {fileID: 0}
159+
m_GameObject: {fileID: 158245195}
160+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
161+
m_LocalPosition: {x: 0, y: 0, z: 0}
162+
m_LocalScale: {x: 1, y: 1, z: 1}
163+
m_Children: []
164+
m_Father: {fileID: 0}
165+
m_RootOrder: 2
166+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
124167
--- !u!1 &521541034
125168
GameObject:
126169
m_ObjectHideFlags: 0

README.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Other patterns:
3333

3434
20. [Decorator](#20-decorator)
3535
21. [Factory](#21-factory)
36+
22. [Facade](#22-facade)
3637

3738

3839
# Patterns from the book Game Programming Patterns
@@ -374,6 +375,8 @@ When making your game you use many standardized methods to for example generate
374375

375376
* [Singleton](#5-singleton). Both provide a global access to an object. So the problems with the Singleton also applies to this pattern.
376377

378+
* [Facade](#22-facade). Is very similar, and you can use Facade in combination with Service Locator.
379+
377380

378381

379382
## 16. Data Locality
@@ -509,7 +512,25 @@ If you are creating several different factories, then they should inherit from s
509512

510513
**Related patterns**
511514

512-
* [Prototype](#4-prototype). The Prototype pattern is generally used if you want to make a copy an existing object, while the Factory pattern is generating new objects. But some argue you can put the Prototype pattern inside of the Factory pattern.
515+
* [Prototype](#4-prototype). The Prototype pattern is generally used if you want to make a copy an existing object, while the Factory pattern is generating new objects. But some argue you can put the Prototype pattern inside of the Factory pattern.
516+
517+
518+
519+
## 22. Facade
520+
521+
When you have several classes and want to make it simpler to access methods in those classes.
522+
523+
**How to implement?**
524+
525+
Create a new script that includes methods which accesses the needed methods in the classes you want a simple access to.
526+
527+
**When is it useful?**
528+
529+
* In games it's common to write standardized code libraries, such as a library for the AI, which includes pathfinding, etc. These tend to include massive amounts of methods in subfolders. To make it easier for yourself you create a script that includes access to the most important methods you need, such as get a path. An example of this can't be found here but in another open source library I have: [Computational geometry](https://github.com/Habrador/Computational-geometry). For example, there are multiple methods on how to generate a Delaunay triangulation. To simplify the access to those methods I wrote a class called _Delaunay, which accesses each Delaunay method in a simple way. Otherwise you would have to first go into the Delaunay folder and figure out which class is doing what and which method you should use to generate the needed triangulation.
530+
531+
**Related patterns**
532+
533+
* [Service Locator](#15-service-locator). Is very similar but the Service Locator is not necessarily consisting of several classes - the service we want to get might consist of a single class. But the Service Locator can use the Facade Pattern if needed.
513534

514535

515536

0 commit comments

Comments
 (0)