我以前使用过这个想法。我用它作为模型。 dataModel - 或者其中一个有效的骨干存储你的对象 - 或对你的对象的引用。这非常有用,因为您可以随时找到某些内容,而无需在课程中漫步。
我已经将它用作单例 - 因此您不必担心可能会创建新版本的dataModel并引用空白对象。有点让你挠了几个小时。 这将是这个样子:
package com.strangemother.models.DataModel
{
private static var _dataModel:DataModel;
/**
an example of storing you items.
*/
public var character:Character;
public static function getInstance():DataModel
{
if(!_dataModel)
{
_dataModel= new DataModel(SingletonLock);
return _dataModel;
}
public function DataModel(lock:Class)
{
if(!lock is SingletonLock)
{
throw new Error("DataModel is a singleton. Use DataModel.getInstance() to use.");
}
}
}
加成@AttackingHobo:
this is a one (1) this is the letter L lowercase (l)
DataModel类似于DataMode1。只是想我会指出。 – AttackingHobo 2010-11-18 23:54:08
我没有说它看起来完全像DataMode1,只是看起来像它。 :) – AttackingHobo 2010-11-20 03:19:52
好 - 你有点儿不错... – Glycerine 2010-11-20 12:46:51