MVC"
m |
|||
Line 1: | Line 1: | ||
{{ZKDevelopersReferencePageHeader}} | {{ZKDevelopersReferencePageHeader}} | ||
− | MVC (Model-View-Control) is a design pattern designed to separate the model, view and controller. It is strongly suggested to apply MVC pattern to your application, no only because the separation of UI from the code, but also easy-to-use and high performance. | + | MVC (Model-View-Control) is a design pattern designed to separate the model, view and controller. It is strongly suggested to apply MVC pattern to your application, no only because the separation of UI from the code, but also easy-to-use and high performance. |
− | In | + | =View= |
+ | The ''view'' is UI. As described in the [[ZK Developer's Reference/UI Composing|UI Composing]] section, UI can be implemented by a ZUML document or in Java. For sake for description, ZUML is used to illustrate the concept and features. | ||
+ | |||
+ | =Controller= | ||
+ | |||
+ | The ''controller'' is a Java program that is used to glue UI (view) and Data (model) together. | ||
+ | |||
+ | For a simple UI, there is no need of controller. For example, the data of a <javadoc>org.zkoss.zul.Listbox</javadoc> could be abstracted by implementing <javadoc type="interface">org.zkoss.zul.ListModel</javadoc>. | ||
+ | |||
+ | For typical database access, the glue logic (i.e., control) can be handled by a generic feature called [[ZK Developer's Reference/Data Binding|Data Binding]]. In other words, the read and write operations can be handled automatically by a generic Data Binding, and you don't need to write the glue logic at all. | ||
+ | |||
+ | To implement a custom controller, you could extend from <javadoc>org.zkoss.zk.ui.util.GenericForwardComposer</javadoc>, or implement <javadoc type="interface">org.zkoss.zk.ui.util.Composer</javadoc> from scratch. Then, specify it in the element it wants to handle in a ZUML document. | ||
+ | |||
+ | =Model= | ||
+ | |||
+ | The ''model'' is the data an application handles. Depending on the application requirement, it could be anything, though usually abstracted as beans and DAO. | ||
+ | |||
+ | In additions to handling the data in a controller, some components supports the abstraction model to uncouple UI and data. For example, [[ZK Component Reference/Data/Grid|grid]], [[ZK Component Reference/Data/Listbox|listbox]] and [[ZK Component Reference/Input/Combobox|combobox]] support <javadoc>org.zkoss.zul.ListModel</javadoc>, while [[ZK Component Reference/Data/Tree|tree]] supports <javadoc>org.zkoss.zul.TreeModel</javadoc>. | ||
{{ZKDevelopersReferenceHeadingToc}} | {{ZKDevelopersReferenceHeadingToc}} | ||
{{ZKDevelopersReferencePageFooter}} | {{ZKDevelopersReferencePageFooter}} |
Revision as of 08:39, 17 November 2010
MVC (Model-View-Control) is a design pattern designed to separate the model, view and controller. It is strongly suggested to apply MVC pattern to your application, no only because the separation of UI from the code, but also easy-to-use and high performance.
View
The view is UI. As described in the UI Composing section, UI can be implemented by a ZUML document or in Java. For sake for description, ZUML is used to illustrate the concept and features.
Controller
The controller is a Java program that is used to glue UI (view) and Data (model) together.
For a simple UI, there is no need of controller. For example, the data of a Listbox could be abstracted by implementing ListModel.
For typical database access, the glue logic (i.e., control) can be handled by a generic feature called Data Binding. In other words, the read and write operations can be handled automatically by a generic Data Binding, and you don't need to write the glue logic at all.
To implement a custom controller, you could extend from GenericForwardComposer, or implement Composer from scratch. Then, specify it in the element it wants to handle in a ZUML document.
Model
The model is the data an application handles. Depending on the application requirement, it could be anything, though usually abstracted as beans and DAO.
In additions to handling the data in a controller, some components supports the abstraction model to uncouple UI and data. For example, grid, listbox and combobox support ListModel, while tree supports TreeModel.