- Unity 2017 Game Optimization(Second Edition)
- Chris Dickinson
- 213字
- 2021-07-02 23:21:09
A globally accessible object
The first requirement makes the Messaging System an excellent candidate for a Singleton object, since we would only ever need one instance of the system. Although, it is wise to think long and hard if this is truly the case before committing to implementing a Singleton.
If we later decide that we want multiple instances of this object to exist, wish to allow the systems to be created/destroyed during runtime, or even wish to create test cases that allow us to fake or create/destroy them in the middle of a test, then it can be difficult task to refactor a Singleton out of our codebase. This is due to all of the dependencies we will gradually introduce to our code as we use the system more and more.
If we wish to avoid Singletons due to the above drawbacks, then it may be easier to create a single instance of the Messaging System during initialization and then pass it around from subsystem to subsystem as needed, or we might wish to go further and explore the concept of Dependency Injection, which attempts to solve problems like these. However, for the sake of simplicity, we will assume that a Singleton fits our needs and design our MessagingSystem class accordingly.
- 程序員修煉之道:程序設計入門30講
- Mastering SVG
- Python從入門到精通(精粹版)
- Internet of Things with Intel Galileo
- C#實踐教程(第2版)
- Protocol-Oriented Programming with Swift
- Python從入門到精通
- UNIX Linux程序設計教程
- 深入剖析Java虛擬機:源碼剖析與實例詳解(基礎卷)
- 嵌入式Linux C語言程序設計基礎教程
- Learning Cocos2d-JS Game Development
- JavaScript Mobile Application Development
- VMware vRealize Orchestrator Essentials
- Mastering High Performance with Kotlin
- OpenCL異構并行計算:原理、機制與優化實踐