The concept of Model locator has been said to store all the value objects (valueobjects, data) in one place and share variables.
In other words, Model Locator is used to centralize the variables needed to manage the program.
The following DEMO15 modellocator.as code is as follows: (the author adds the corresponding annotation)
import mx.collections.ArrayCollection;
[Bindable]
public class ModelLocator
{
//定义程序需要的变量,作者建 议读者把该部分定义放在最下边,而不是示例中的上边,原因就是在于代码更整 齐(因人而异,仅作者的个人建议,呵呵)
public var photoData:ArrayCollection=new ArrayCollection();
public var purchasedPhotos:ArrayCollection=new ArrayCollection();
//定义ModelLocator的Single Instance,这就是设计模式的单例模式(不明白 的读者可以看设计模式中的该模式讲解)
static private var __instance:ModelLocator=null;
//返回single instance
static public function getInstance():ModelLocator
{
if(__instance == null)
{
__instance=new ModelLocator();
}
return __instance;
}
}
For Modellocator's instance and getinstance code, this part of the code is written in the process of writing new code, unless you redefine one of your own modellocator (based on the Imodellocator interface implementation), This part of the code is so written, hehe, even its own definition, it is similar.
For getinstance, it will be judged whether the program already has an instance of Modellocator, and if it is read, it is not created.
The [bindable] feature makes the variable that you define automatically updated wherever you use the defined variable, which is also the concept of modellocator shared variables.
Valueobject under the Photo.as object author does not explain, really no explanation, hehe.
The next talk about the core of the Cairngorm control process, that is, bussiness under the various parts and the complex relationship between the event, may be the reader just contact will feel very winding, it does not matter, oh, step by step, the author explained, the reader will not have that feeling.
The author is very grateful to the broad masses of the reader's support, see everyone's evaluation, the heart is very gratified, hehe.
Article Source: http://wangyisong.javaeye.com/blog/451924