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
+22-1Lines changed: 22 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,6 +33,7 @@ Other patterns:
33
33
34
34
20.[Decorator](#20-decorator)
35
35
21.[Factory](#21-factory)
36
+
22.[Facade](#22-facade)
36
37
37
38
38
39
# Patterns from the book Game Programming Patterns
@@ -374,6 +375,8 @@ When making your game you use many standardized methods to for example generate
374
375
375
376
*[Singleton](#5-singleton). Both provide a global access to an object. So the problems with the Singleton also applies to this pattern.
376
377
378
+
*[Facade](#22-facade). Is very similar, and you can use Facade in combination with Service Locator.
379
+
377
380
378
381
379
382
## 16. Data Locality
@@ -509,7 +512,25 @@ If you are creating several different factories, then they should inherit from s
509
512
510
513
**Related patterns**
511
514
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.
0 commit comments