The Singleton pattern is shown in Figure 5.
Singleton模式如图5所示。
Create a private attribute for the Singleton Pattern called _instance.
为Singleton模式创建私有属性,称为_ instance。
Doing so creates an instance of the Singleton Pattern in the Model Explorer.
执行此操作将会在模型浏览器中生成一个Singleton模式的实例。
The singleton pattern can be used to delay the initialization of an object as long as possible.
单元素模式可以用来尽可能久地延迟对象的初始化。
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类图视图中。
As its name suggests, the Singleton Pattern is typically used when you want only one instance of a particular class.
如其名称所暗示的,当您想要特别类的仅仅一个实例时,才使用Singleton模式。
To facilitate this, the plug-in class implements the singleton pattern: It stores a reference to itself in a private class variable.
为了使这一点更方便,插件类实现单模式(singleton pattern):它在私有类变量中存储一个自身的引用。
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 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。
Typical examples include a cached DAO, cache of JNDI references, or any sort of common factory or other component that needs to use the Singleton pattern.
典型的例子有:缓存的DAO,JNDI引用的缓存,或者任何类型的公共工厂或者其他需要使用Singleton模式的组件。
Using the Singleton pattern we guarantee that no matter how many times the BusinessLayerProxy tries to create a CommandFactory, only one instance will exist.
使用Singleton模式,我们可以保证无论BusinessLayerProxy多少次尝试建立CommandFactory,也只存在一个实例。
This is a class that can be used repeatedly to instantiate a class as a singleton without having to re-write the singleton pattern code for that specific class.
这是一个可用来创建单例类实例确不需要为每个特定的类重写单例模式代码的可重用的类。
Since there can be only one un-caught handler per process active at a time, the constructor should be invoked only once; hence, the reason for the singleton pattern.
因为每次只能有一个未捕获的处理程序处理一个活动进程,构造函数应该只被调用一次,因此要采用singleton模式。
The singleton pattern ensures that only a single instance of a class is normally used by an application, but still allows alternate instances to be created as required.
单元素模式可以确保应用程序通常只使用类的单个实例,但是仍然允许根据需要创建备用实例。
Unless the Settings wrapper class is designed using the singleton pattern, there can be multiple instances of the same application Settings class in a single application.
除非使用单一实例模式来设计设置包装类,否则单个应用程序中可能存在同一个应用程序设置类的多个实例。
The framework we'll create is a simple 3-tier framework that processes business logic using three patterns: the 3-layer architecture pattern, the Singleton pattern, and the Command pattern.
我们将要建立的是一个简单的3-tier框架,它使用了三种模式处理业务逻辑:3-layer体系结构模式、Singleton模式和Command模式。
The Singleton creation pattern is a common programming idiom.
单例创建模式是一个通用的编程习语。
It is often seen as an antidote for many of the problems that using Singleton brings in its wake (and, as an aside, Singleton was one pattern we did _not_ include in the book :->).
它常常被视为使用Singleton之后带来的许多问题的解毒剂(并且,作为题外话,Singleton是我们没有包含在本书中的一个模式:->)。
Through this functionality, you can use the popular singleton pattern.
通过使用这种功能,您可以使用流行的单例模式。
The singleton is a useful design pattern for allowing only one instance of your class, but common mistakes can inadvertently allow more than one instance to be created.
单例模式是一种非常有用的设计模式,它允许你的类对外只提供一个实例,但是常犯的错误在于不止一个实例被创建。
This is demonstrated using the ExceptionHandler class, which again adopts a singleton design pattern.
使用exceptionhandler类可以展示这一点,该类也采用了singleton设计模式。
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的实例都是同样的。
They also explore problems with common idioms such as the static singleton anti-pattern and solutions using dependency injection, and examine scopes for web applications and other purposes.
5 - 6章还探究了一些常见问题例如静态单例反模式以及使用依赖注入的解决方案,并调查了web应用和其它应用的范围。
For example, according to the pattern catalog, the State pattern is often related to Flyweight and Singleton [GoF].
例如,通过模式目录,State模式经常涉及到Flyweight和Singleton [g oF]。
You will design the object as a singleton (this design pattern will limit this object to a single instance) and have the appropriate retrieve and store methods to manipulate the cache.
您将把对象设计为一个单子实例 (singleton)(这个设计模式将把这个对象限制在一个单个实例中)并使用合适的检索和存储方法对高速缓存进行操作。
Classes implementing Singleton pattern will ensure that only one instance of the object ever exists at any one time.
使用类来实现单例模式可以确保在任何时间只有一个实例对象。
Finally, the application of singleton pattern is depicted in this system.
最后,描述了单体模式在系统中的应用。
The basic thing comes in my mind is either Singleton or Factory Pattern.
基本的事情出现在我的脑海里是单件或工厂模式。
The basic thing comes in my mind is either Singleton or Factory Pattern.
基本的事情出现在我的脑海里是单件或工厂模式。
应用推荐