People who have used Flex know that there is a PureMVC framework based on MVC, a framework that is popular because it is small and simple.
The PureMVC framework has a clear goal of dividing the program into three layers of low coupling: Model, view, and controller. Reducing the coupling between modules and how each module works together is important for creating easily scalable, maintainable applications. In the classic MVC design pattern implemented by PureMVC, these three parts are managed by three single case mode classes, respectively model, view and controller. The three are collectively called core or core roles. There is also a single example pattern class in PureMVC-facade,facade provides the only interface to communicate with the core layer to simplify development complexity.
Here, let's put this PureMVC in the famous picture:
Here is a brief introduction to PureMVC some simple knowledge, the details can be viewed puremvc.org. Here we do not talk about his principles, just an example to simply say how the PureMVC mechanism to run a swing project.
Back to the focus of this article, because the PureMVC is small and simple, so the author has translated him into C#,coldfusion,haxe,java, JavaScript, objective C, PHP, Python, Ruby, So now we will be based on Java to do a demo to talk about the operating principle of PureMVC. This example is a simple implementation of a small system, first pop-up a dialog box, enter the user name and password successfully entered the system, for related operations, all actions are using PUREMVC mechanism to send messages, to do MVC three layer model, view and controller separation.
From the figure above, we know that the entrance to the program is a façade, this class is a single class, we will inherit this class to rewrite the façade, when the program started with us to register commands and other related information. All the information sent through him to send. In use, we usually inherit his Initializecontroller method for loading initialized Command, such as clicking on the menu to open an interface information, are here in advance registration, such as code:
public class ApplicationFacade extends Facade {
private static ApplicationFacade instance= null;
protected ApplicationFacade(){
super();
}
public static ApplicationFacade getInstance(){
if(instance == null)
instance = new ApplicationFacade();
return instance;
}
@Override
protected void initializeController() {
super.initializeController();
/** *//**
* 注册初始化的Command
* **/
registerCommand(ApplicationConstants.INITSTAR, InitStartCommand.class);
}
/** *//**
* 系统初始化完毕后调用这个发送INITSTAR,监听这个命令的Command
* 就会加载所有的Command
* **/
public void startup(){
sendNotification(ApplicationConstants.INITSTAR, null, null);
}
}