The Singleton pattern is shown in Figure 5.
Singleton模式如图5所示。
The Singleton creation pattern is a common programming idiom.
单例创建模式是一个通用的编程习语。
Create a private attribute for the Singleton Pattern called _instance.
为Singleton模式创建私有属性,称为_ instance。
It is actually the real name of the singleton instance of the Unit type!
事实上这是Unit类型单体实例的真正名字!
Doing so creates an instance of the Singleton Pattern in the Model Explorer.
执行此操作将会在模型浏览器中生成一个Singleton模式的实例。
This is important because the singleton aspects are typically not garbage collected.
这一点很重要,因为单体的方面通常不会被垃圾收集。
Being close to wild roses in appearance, the singleton fits the unfussy modern garden.
这种样子和野生蔷薇差不多的品种可以种植在那些不是很讲究的现代花园。
The singleton pattern can be used to delay the initialization of an object as long as possible.
单元素模式可以用来尽可能久地延迟对象的初始化。
When copies of the singleton class run in multiple VMs, an instance is created for each machine.
当单例类的副本运行于多个虚拟机中时,每个虚拟机都会为其创建一个实例对象。
The constructor of BookWebApp gets the singleton instance of the book service implementation object.
BookWebApp的构造函数获取这个图书服务实现对象的singleton实例。
To create an instance of the Factory Method Pattern, perform the same steps as for the Singleton Pattern.
要创建Factory方法模式的实例,执行同Singleton模式相同的步骤。
Drag and drop the Singleton Pattern instance from the Pattern Explorer into the UML Class Diagram view.
将Singleton模式实例从模式浏览器中拖拽到UM l类图视图中。
Lines CA and D0 represent the inline constructor storing the values true and 5 into the Singleton object.
CA和d0行表示内联的构造函数,该构造函数将值true和5存储到Singleton对象。
The major disadvantage of using a Singleton, as we did here, is that you must clear the Singleton between each test.
正如我们在此所做的,使用Singleton的主要缺点是:您必须在各次测试之间清除Singleton。
As its name suggests, the Singleton Pattern is typically used when you want only one instance of a particular class.
如其名称所暗示的,当您想要特别类的仅仅一个实例时,才使用Singleton模式。
Since an instance of a subclass is an instance of your superclass, you could find multiple instances of the singleton.
由于子类的实例也是单例类的实例,所以可能出现多个单例实例并存的情况。
The code at BE allocates the memory from the heap for the Singleton object and stores a pointer to that memory in eax.
be处的代码为Singleton对象从堆中分配内存,并将一个指向该块内存的指针存储到eax中。
Listing 4 shows a version of the singleton that USES a method instead of an attribute to specify the appropriate class.
清单4显示了使用方法而非属性来指定适当类的单例。
Thread 1 completes the initialization of the Singleton object by running its constructor and returns a reference to it.
线程1通过运行Singleton对象的构造函数并将引用返回给它,来完成对该对象的初始化。
Having this method available can be helpful in the application in general because now the singleton becomes easily mutable.
总之,在应用程序中增加这个方法是很有用的,因为我们现在可以轻松地修改单一实例。
To facilitate this, the plug-in class implements the singleton pattern: It stores a reference to itself in a private class variable.
为了使这一点更方便,插件类实现单模式(singletonpattern):它在私有类变量中存储一个自身的引用。
The singleton provides us with the means to store another object that is used for the aggregation done in each UDF in the SQL statement.
单件为我们提供了一种可以将SQL 语句中每一个UDF 进行聚集计算时需要的数据存储在另外的对象当中的方式。
Most caches are implemented using the Singleton pattern involving a static reference to a top level cache class as shown in this example.
使用Singleton模式实现的大多数缓存都涉及本例所示的对顶级cache类的静态引用。
The problem with this line of code is that the variable instance can become non-null before the body of the Singleton constructor executes.
这行代码的问题是:在Singleton构造函数体执行之前,变量instance可能成为非null的。
The singleton, builder, and factory method design patterns are considered creational patterns, as they assist in the construction of objects.
单例、生成器和工厂方法设计模式被视为是创建型的模式,因它们可协助对象的构建。
The only other method (set in italics) in the class is used to get a reference to the singleton and to create it if it is not yet instantiated.
该类中仅剩的另一个方法(用斜体标识)用于获取该单件的一个引用,如果尚未实例化则创建它。
A simple optimization to this code would be to apply the Singleton design pattern to class Empty, because every instance of Empty is identical.
这段代码的一个简单优化是对empty类应用同一个设计类型,因为每一个Empty的实例都是同样的。
If you add database connections or use a JDBC driver that allows multithreading, the singleton can be easily adjusted to allow more connections.
当你增加数据库连接或者改而使用支持多线程的JDBC驱动器时,单例模式能够很容易地适应这一变化。
The singleton pattern is probably one of the most often used OOP design patterns; it restricts the number of object instances of a class to one.
单例模式可能是最常用的OOP设计模式之一了;它限制了一个类的对象实例数只能为1。
Then it shows how PHP V5.3's LSB feature resolves those issues, while showing implementations of the singleton and active record design patterns.
然后展示了PHPV5.3的LSB特性,并给出了单例和活动记录设计模式。
应用推荐