# Table Of Contents
Contents
Introducing design patterns 6
Using this guide 8
The sample project. 8
The SceneBootstrapper 10
The SOLID principles 12
Single-responsibility principle 13
Example: Sample project. 17
Open-closed principle 17
Example: Sample project. 22
Liskov substitution principle 23
Example: Sample project. 30
Interface segregation principle 31
Example: Sample project. 33
Serializing interfaces 34
Dependency inversion principle 36
Example: Sample project 41
Interfaces versus abstract classes 43
Abstract classes. 43
Interfaces 45
A SOLID understanding 47
Design patterns for game development 48
The Gang of Four 48
Learning design patterns 49
Further reading 50
Patterns within Unity 50
Factory pattern 51
Example: A simple factory 52
Pros and cons 55
Improvements 56
Object pool. 57
Example: Simple pool system 58
UnityEngine.Pool. 62
Pros and cons 64
Improvements 65
Singleton pattern 66
Example: Simple singleton 67
Persistence and lazy instantiation. 68
Using generics. 70
Pros and cons 72
Command pattern 73
The command object and command invoker 74
Example: Undoable movement 75
Pros and cons 78
Improvements 78
State pattern 80
States and state machines 80
Example: Simple state pattern. 82
Pros and cons 87
Improvements 87
Example: Game states 89
Explore the QuizU Project 92
Observer pattern. 93
Events 94
Example: Simple subject and observer 95
Naming conventions. 97
UnityEvents and UnityActions 99
Pros and cons 100
Improvements 100
Model View Presenter (MVP) 102
Model View Controller (MVC) design pattern. 102
Model View Presenter (MVP) and Unity 103
Example: Health interface 104
MVP in Unity UI. 108
Pros and cons 109
Model-View-ViewModel 110
MVVM in Unity 6 111
Data binding 111
Example: Updated sample project. 112
Data binding: UI Builder. 113
Data binding: Scripting 117
Pros and cons 120
Strategy pattern. 121
Example: An ability system 122
Before refactoring 122
Implementing the strategy pattern. 124
Example: Sample project 126
Pros and cons 127
More examples 127
Flyweight pattern. 128
Unrefactored example 129
Implementing the flyweight pattern 131
Example: Sample project 132
Prefabs versus flyweights. 135
Pros and cons 136
More examples 136
Dirty flag 137
Example: Sample project 138
Pros and cons 143
Dirty flags versus dirty bits and caching 143
More examples 143
Conclusion 145
Other design patterns 146
A series of advanced resources for Unity programmers . 147