Design of J2ME application framework based on MVC pattern

Source: Internet
Author: User

1 The status of the J2ME application framework

In June 1999, Sun launched the J2ME (Java 2 Microedition,java 2 Pocket edition). J2ME is specially developed for devices that use limited power, limited network connectivity, and limited graphical user interface capabilities to meet the needs of consumer electronics and embedded device development.

Today, 7 years later, consumer electronics and embedded devices have developed rapidly. Hardware equipment faster and faster, storage capacity is also more and more large, which naturally led to the development of software. MIDP 2.0 and CLDC 1.1 have also come out in succession, and a variety of JSR are emerging.

The rapid development of hardware platform and software platform has naturally driven the growth of people's demand, which makes the application more and more complex now. Take mobile games as an example: previous mobile games, the general code must be limited to the number of KB, and now the majority of mobile phone restrictions have been canceled. Hundreds of KB of games are already common and even some J2ME games have more than 2 MB.

Generally speaking, J2ME programs are relatively small, most of which are below KB. And most of them are pictures and sounds, and the code only takes up a small part of it. In order to improve the execution efficiency of J2ME programs, the usual practice is to complete the entire application with only one class, and to complete all interface switching in the callback function Commandaction (). For example:

The benefits of this pattern are minimal code, the smallest jar package size, and the highest efficiency in execution, and because all interfaces are in the same class, they can easily share data.

But if the interface is a lot, the program is very large, this model reflects its disadvantage. On the one hand, thousands of lines of code are concentrated in a class, debugging and maintenance is very inconvenient. On the other hand, because many interfaces share data in the same class, their coupling is greatly improved. If you want to replace or modify one of these interfaces, it is likely to affect other interfaces. This brings a lot of inconvenience to the development process.

With the development of embedded hardware, the complexity of J2ME software becomes more and more complicated, and the design pattern can not meet the needs of embedded development. This requires a better design pattern to replace the previous simple design pattern. Here's how to apply the MVC design pattern to J2ME programming.

2 Introduction to the MVC pattern

MVC, proposed by Trygve Reenskaug, is first applied to the SMALLTALK-80 environment and is the foundation of many interactive and interface systems, and Microsoft's MFC base classes follow the idea of MVC. This model is now very mature and widely used in the development of Web application, and the Apache Open source project struts is a typical example.

The English full name of MVC is Model-view-controller, that is, the input, processing and output flow of an application are separated according to model, View and Con-troller. Such an application is divided into 3 layers-the model layer, the view layer, and the control layer.

The separation of models, views, and controllers allows a model to have multiple display views. If a user changes the model's data through a controller of a view, then all other views that depend on the data should reflect these changes. Therefore, whenever a data change occurs, the controller notifies all views of the change and implements the updated display. This is actually a model of the change of one propagation mechanism. The relationships between models, views, controllers, and their respective main functions are shown in Figure 1.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.