The API is straightforward: You call a singleton method and get back a connection object.
API很直观:您调用单个方法,并返回一个连接对象。
The DefaultDAO class stores an instance of itself (as a Singleton) in the static variable instance, allowing access to that instance through the getInstance() method.
DefaultDAO 类在静态变量instance 中存储了它自己的一个实例(存储为Singleton),并允许通过getInstance()方法访问该实例。
The static getInstance method contains the template code for a singleton.
静态getInstance方法包含单例的模板代码。
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.
该类中仅剩的另一个方法(用斜体标识)用于获取该单件的一个引用,如果尚未实例化则创建它。
This method in turn creates the container (which ACTS as a singleton) and registers components and their parameters.
这个方法然后再创建容器(充当单体)并注册组件和组件的参数。
The singleton, builder, and factory method design patterns are considered creational patterns, as they assist in the construction of objects.
单例、生成器和工厂方法设计模式被视为是创建型的模式,因它们可协助对象的构建。
Having this method available can be helpful in the application in general because now the singleton becomes easily mutable.
总之,在应用程序中增加这个方法是很有用的,因为我们现在可以轻松地修改单一实例。
Listing 4 shows a version of the singleton that USES a method instead of an attribute to specify the appropriate class.
清单4显示了使用方法而非属性来指定适当类的单例。
Now, we can call the reset method to start off each test run to ensure we are going through the initialization code for the singleton object on every test run.
现在,我们可以在每次测试之前调用reset方法,保证我们在每次测试过程中都会先执行singleton对象的初始化代码。
To create an instance of the Factory Method Pattern, perform the same steps as for the Singleton Pattern.
要创建Factory方法模式的实例,执行同Singleton模式相同的步骤。
To create an instance of the Factory Method Pattern, perform the same steps as for the Singleton Pattern.
要创建Factory方法模式的实例,执行同Singleton模式相同的步骤。
应用推荐