通过使用这种功能,您可以使用流行的单例模式。
Through this functionality, you can use the popular singleton pattern.
单例模式是一个非常复杂的 问题。
Singleton is bit complex, but it plays very important role in game development.
另一个选择是使用单例模式。
这些都在单例模式和原型模式中定义了。
单例模式有点复杂,但它在游戏开发中非常有用。
Singleton is bit complex, but it plays very important role in game development.
我坚信,在大多数的框架中,使用单例模式时,考虑得都太少了。
It is my true belief that Singleton patterns have been used with far too little thought in most frameworks.
单例模式:确保一个类只有一个实例,并提供一个全局访问点。
The Singleton Pattern:ensures a class has only on instance, and provides a global point of access to it.
使用类来实现单例模式可以确保在任何时间只有一个实例对象。
Classes implementing Singleton pattern will ensure that only one instance of the object ever exists at any one time.
不同于书本和培训课程中所提的单例模式,真正的企业具有非常复杂的数据架构。
Unlike the simplistic models in books and training courses, a real enterprise has a very complicated data architecture.
单例模式确实能够轻而易举解决无须对每个类的引用都进行存储的问题。
They easily solve the problem of not having to store references to every class.
单例模式是一种有用的控制类访问的途径,他能保证只有一个类实例存在。
Singletons are a useful way to control access to a class, making sure that only one instance can exist.
单例模式同样用于控制像数据库连接或者sockets这样的资源访问。
Singletons often control access to resources such as database connections or sockets.
这是一个可用来创建单例类实例确不需要为每个特定的类重写单例模式代码的可重用的类。
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.
单例模式可能是最常用的OOP设计模式之一了;它限制了一个类的对象实例数只能为1。
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.
相反,Scala支持单例模式,可以应用于那些一种类型只有一个实例的情况。
Instead, Scala supports a singleton object construct to support those cases where exactly one instance of a type is needed.
这通常对描述符起到不好的影响,使它类似于一个单例模式(singleton)。
This has the usually undesirable effect of making the descriptor something like a singleton. For example.
同时,如果使用创建单实例的方法实现单例模式,单例类还具有创建多个实例的变通能力。
Likewise, with a singleton implemented as single instance, you leave open the possibility of altering the class to create more instances in the future.
这样分离出单例结构的代码,将有利于保持按单例模式使用类或不按单例模式使用类的灵活性。
This has the added benefit of separating singleton code from the class code leaving the flexibility to use several instances of the class or using the class as a singleton.
前面已经简单地介绍了单例模式的实现方式,现在让我们进入主题:两个单例对象如何同时存在?
Now that we've looked briefly at implementation, let's turn to the heart of this article: how two singletons can exist simultaneously.
最后,在单例模式的一些实现方式中,单例类的子类能够动态地重载方法,这是静态方法所不能办到的。
With some implementations of the singleton, you allow writers of subclasses to override methods polymorphically, something not possible with static methods.
接下来,UnitsConverter也是一个单例模式,因为它是使用object关键词定义的。
Next, UnitsConverter is also a singleton as it is defined using the object keyword.
当你增加数据库连接或者改而使用支持多线程的JDBC驱动器时,单例模式能够很容易地适应这一变化。
If you add database connections or use a JDBC driver that allows multithreading, the singleton can be easily adjusted to allow more connections.
本文讨论的主题是单例模式,请将上述实现方式牢记于心,因为接下来的现象可能出现在任何一种实现方式中。
As I discuss the singleton, keep the above implementations in mind, although many of those phenomena can occur for any implementation of the singleton.
单例模式的目的在于控制对象的创建,限制对外提供的对象数量为1,同时允许在情况变化时创建更多的实例。
The singleton's purpose is to control object creation, limiting the number to one but allowing the flexibility to create more objects if the situation changes.
单例模式是一种非常有用的设计模式,它允许你的类对外只提供一个实例,但是常犯的错误在于不止一个实例被创建。
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.
在讨论了如何实现单例模式之后,我会逐一介绍这些时而出现的诡异现象,讲解它们是怎么出现的以及如何去避免犯错。
After discussing how to implement the singleton, I'll go over the sometimes surprising causes for the phenomena one by one, showing you how they occur and how you can avoid making those mistakes.
单例模式-每个依赖服务的组件,都是获得服务工厂生成单个实例的引用。服务是一个单例对象或函数,对外提供特定的功能。
Singletons - Each component dependent on a service gets a reference to the single instance generated by the service factory.
这使得它们使用起来非常方便,但如果确实想要构建一个部件化、组件化的环境,单例模式用起来就不一定那么舒服了,有可能会坏事。
This makes them very convenient, but they can come back to bite you if you are truly building for a widgetized, componentized environment.
单例创建模式是一个通用的编程习语。
The Singleton creation pattern is a common programming idiom.
单例创建模式是一个通用的编程习语。
The Singleton creation pattern is a common programming idiom.
应用推荐