| Software Design PatternsIt's harder to read code than to write it. - Joel Spolsky |
| Singletonone-instance, global-access, creation on demand, runtime-initialization, supports inheritance if wrongly used as "helper" class = decrease-readability, promotes-coupling concurrency-unfriendly, can not know when initialization will happen Alternative = Pass instance, Store instance in base class, global class, Service Locator |
| Flyweightefficiently-reuse-objects , share large numbers of similar objects, save memory. splits the state into intrinsic (shared) and extrinsic (unique) parts Game Development, Networking Applications, Text Editors Interface → Implementation stores intrinsic state ← Factory ← Client stores extrinsic state |
Serializationobject to stream-of-bytes. Storable in memory, a database, or a file. | |
| Empty ScriptableObject for Enum like comparison! Easier to extend. | Scriptable ObjectsUnity, data containers for shared data, static game configuration data, "read-only" persistent data. First-class objects, reduce memory usage, assign to variable, pass as argument, method return, data type in data structures, serialiable, dynamic creation/destruction at runtime. Can change values at runtime but maintains new values after execution termination. Supports Unity events Awake, OnEnable, OnDestroy, OnDisable, OnValidate and Reset . Inventories. Enemy, player, or item statistics. Audio collections data containers = data that does not need to change at runtime To avoid tampering = Encryption. Digital signatures (fingerprint algorithm to verify). Server-side validation (Authority rejects anything manipulated) |
Finite State Machineone state at any moment in time , finite number of states, decompose an object's behavior into 'chunks' or states.
| |
| DecoratorWrapper pattern, Wrap around objects, add behaviour to **individual objects** without affecting the behaviour of other objects of same class. Different characters - with same base spells - but merge with different spells. Controller = Object creation using factory, Call Manager, Cast Spell Manager = Singleton = Merge two abilities |
Command PatternAction Pattern, method call &=rarr a stand-alone object. Everything needed to execute that command is available to the class Instead of directly calling a method to perform an action, you create a command object that holds all the information needed to execute that action. | |
Entity-Component SystemECS, Components are pure classes, almost entirely for data. | |
MVCdecouples views and models. multiple views to attach to a model. Nestable, Utilizes Observer and Composite patterns Controller class = implement response statergy = [Statergy Pattern](#statergy) Factory Method = specify controller class Decorator = add scrolling to view | |
| Broker Chain Pattern |