在blakcberry实现单态
来源:互联网 发布:音量放大软件中文版 编辑:程序博客网 时间:2024/05/29 07:14
按传统j2se的写法折腾了n久都不行,终于发现了一个官方例子:
Details
An application may require one or more singleton objects to be accessed from within the application itself or by other applications. The static variable ‘_instance’, in the sample below, is initialized to null for each process running on the system. Therefore, the getInstance() method needs to check the ‘_instance’ variable each time it is invoked.
To create a singleton using the RuntimeStore, use the following sample:
import net.rim.device.api.system.*;
class MySingleton {
private static MySingleton _instance;
private static final long GUID = 0xab4dd61c5d004c18L;
// constructor
MySingleton() {}
public static MySingleton getInstance() {
if (_instance == null) {
_instance = (MySingleton)RuntimeStore.getRuntimeStore().get(GUID);
if (_instance == null) {
MySingleton singleton = new MySingleton();
RuntimeStore.getRuntimeStore().put(GUID, singleton);
_instance = singleton;
}
}
return _instance;
}
}
Use Cases
A singleton based on the above sample code might be used in the following scenarios:
- A network manager class that handles all network-related requests for an application
- A packet/message sender class
- A debugging/logging class
- 在blakcberry实现单态
- 单态设计模式在 PHP5 中的实现方式
- 在Flex/ActionScript3中实现单例
- 在表格中实现一列单选
- 在Gridview中实现RadioButton单选
- 在repeater中实现radiobutton单选
- 在Java中的单例实现方式
- 在 Swift 中实现单例方法
- ParaView在单页面下实现MPR
- CheckBox在listview中实现单选
- 在 Python 中实现单例模式
- 在 Python 中实现单例模式
- 在 Python 中实现单例模式
- 在 Python 中实现单例模式
- 利用宏实现单例(在宏中写实现方法)
- C++ 单态模式实现
- 在DataGrid中添加Radio实现单选
- 在DataGrid中添加Radio实现单选
- 观战朝鲜vs巴西后,给中国足球的两点建议
- 0--我的串口发送"hello word"程序
- 344332423432432432
- 2010-6-16
- Asterisk卡常见问题汇总
- 在blakcberry实现单态
- 发布NES/FC背景地图编辑器
- 面试中你必须要知道的语言陷阱
- javascript中文编码/解析与C#ASP.NET中文编码/解析 C#: Server.UrlEncode() HttpUtility.UrlEncode() javascript: escape() encodeURI() encodeURICom
- C/C++笔试、面试题目大汇总----转贴
- NetBeans 6.9 正式版发布!
- PDFMaker无法找到Adobe PDF Printer的打印机驱动
- BOSS
- 语义web与本体经典论文