1
- Singleton 单例模式 <Alpha version >
1
+ Singleton 单件模式 <Alpha version >
2
2
============================
3
3
4
4
This chapter is an anomaly. Every other chapter in this book shows
@@ -614,7 +614,7 @@ instances of `BulletManager` do you need?
614
614
The answer here is * zero* , actually. Here's how we solve the "singleton" problem
615
615
for our manager class:
616
616
617
- 答案是* 零* ,实际上,我们是这样解决我们管理类的"单例 "问题的:
617
+ 答案是* 零* ,实际上,我们是这样解决我们管理类的"单件 "问题的:
618
618
619
619
620
620
```
@@ -641,7 +641,7 @@ There we go. No manager, no problem. Poorly designed singletons are often
641
641
that behavior into the class it helps. After all, OOP is about letting objects
642
642
take care of themselves.
643
643
644
- 就这样。没有管理器也没有问题。错误的设计单例通常会 “帮助”你将功能添加到别的类中。如果可以,你只需将这些功能移动到它帮助的类中去就可以了。比较,面向对象就是让对象自己管理自己。
644
+ 就这样。没有管理器也没有问题。错误的设计单件通常会 “帮助”你将功能添加到别的类中。如果可以,你只需将这些功能移动到它帮助的类中去就可以了。比较,面向对象就是让对象自己管理自己。
645
645
646
646
Outside of managers, though, there are other problems where we'd reach to
647
647
Singleton for a solution. For each of those problems, there are some alternative
@@ -736,7 +736,7 @@ instantiation is only done at *runtime*. The Singleton pattern, in contrast,
736
736
guarantees a single instance at compile time by the very nature of the class's
737
737
structure.
738
738
739
- 这份实现的不足之处在它只在* 运行期* 检测来防止多个实例。单例模式 ,相反的,在编译期就通过类结构自然的保证了单个实例。
739
+ 这份实现的不足之处在它只在* 运行期* 检测来防止多个实例。单件模式 ,相反的,在编译期就通过类结构自然的保证了单个实例。
740
740
741
741
### To provide convenient access to an instance 提供一个便利的方法访问实例
742
742
@@ -745,7 +745,7 @@ to get our hands on an object we need to use in a lot of different places. That
745
745
ease comes at a cost, though -- it becomes equally easy to get our hands on the
746
746
object in places where we * don't* want it being used.
747
747
748
- 便利的访问是我们使用单例额主要原因 。它让我们在许多不同地方得到一个对象变得简单。这种便利也有代价,——它也是的我们在不想使用的地方也可以轻松的得到这个对象。
748
+ 便利的访问是我们使用单件额主要原因 。它让我们在许多不同地方得到一个对象变得简单。这种便利也有代价,——它也是的我们在不想使用的地方也可以轻松的得到这个对象。
749
749
750
750
The general rule is that we want variables to be as narrowly scoped as possible
751
751
while still getting the job done. The smaller the scope an object has, the fewer
0 commit comments