我以前使用過這個想法。我用它作爲模型。 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