除了实例及其get方法之外,Singleton类的其他成员还有什么用途? [英] What are the purposes of other members of a Singleton class besides the instance and its get method?

查看:47
本文介绍了除了实例及其get方法之外,Singleton类的其他成员还有什么用途?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自GoF的设计模式

参与者

Singleton

  • 定义了 Instance 操作,该操作使客户端可以访问其唯一实例 uniqueinstance . Instance 是一个类操作(即,Smalltalk和C ++中的静态成员函数.)

  • defines an Instance operation that lets clients access its unique instance uniqueinstance. Instance is a class operation (that is, a class method in Smalltalk and a static member function in C++).

可能负责创建自己的唯一实例 uniqueinstance .

may be responsible for creating its own unique instance uniqueinstance.

合作

•客户仅通过 Singleton 的权限访问 Singleton 实例 uniqueinstance Instance 操作.

• Clients access a Singleton instance uniqueinstance solely through Singleton's Instance operation.

Singleton 类中, uniqueinstance 是唯一实例,而 Instance()是其get方法.

In Class Singleton, uniqueinstance is the unique instance, and Instance() is its get method.

其他成员的目的是什么

  • 方法 SingletonOperation()
  • 方法 GetSingletonData()
  • field singletonData ?

谢谢.

推荐答案

没什么特别的,或者说与 Singleton 无关,您可以删除它或重命名它或任何其他方式喜欢.这只是一种普通方法,与您作为 Singleton 的班级没有任何关系.

Nothing in particular, or rather say it has nothing to do with Singleton , you can just remove it or rename it or whatever you like. It's just a normal method and has nothing to do to your class being a Singleton.

这篇关于除了实例及其get方法之外,Singleton类的其他成员还有什么用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆