Construct an artistic mobile development framework (KJAVA) based on the MVC + Observer Model (I)

Source: Internet
Author: User
Build based on MVC + Observer Pattern and artistic mobile development framework ( KJAVA Version) Author: Sun Dongfeng Date: 29/11/2007I have been developing a mobile platform for several years without knowing it. I have been familiar with kjava, Symbian, and Windows Mobile Platforms, have played games, and have also done applications, most of which are online. I often try to port code between different platforms. Java to C ++, C ++ to Java, most of the time is wasted on the inconsistency of the platform framework. Mobile development platforms are emerging one after another. Following the previous kjava, brew, Symbian, palm, Linux, and Windows Mobile, gphone and iPhone platforms have successively emerged. As you can imagine, there will be more and more mobile development platforms in the near future. As a result, I often think in my spare time that if there is such a framework, every company will adopt this open-source framework for program architecture, which will save programmers a lot of exhausted brain cells! Of course, such an open source set should first be beautiful and artistic. I have been thinking about how to use the artistic perspective to look at programming. Everyone has a heart of beauty. Every time I read code that is broken by other people's hierarchies, I can't help but feel impetuous. More often I can't read it in half. As a programmer's communication tool, the program cannot fully play its due role. However, an artistic code should resonate with those of Later users. Art is concise and elegant. In this document, I tried to build such an artistic mobile development framework. It has Java and C ++ versions, therefore, porting between the kjava platform and the Symbian and Windows Mobile platforms can save at least a lot of effort. More importantly, if you can understand this framework, it is easier and more convenient for programmers to communicate with each other. This is just a good wish for me. Of course, I have limited capabilities and may not be able to write such a great framework. Therefore, I hope more colleagues will give more comments, "What about the three stinks! ". I first built the kjava mobile development framework. After this version is completed, I will start developing the Symbian version framework, you can refer to an article I wrote earlier: Symbian The art of Software ProgrammingSo what kind of framework is the artistic framework of http://blog.csdn.net/dongfengsun/archive/2007/04/08/1556704.aspx? In my limited understanding and development experience, I think an artistic framework should have the following main features: 1. Highly separated interfaces and data, that is, the interface display and data processing are completely separated, and their coupling degree is minimized. II. The framework should be easy to understand, and the design mode should be the main tool for communication between programmers. It should play an important role in the Framework Design, our framework Design mainly adopts the MVC + Observer mode (here we also use MVC as one of the Design Pattern ). Iii. Code should be well scalable. The divestiture and replacement of any module will not have a big impact on other modules. Of course, for example, the three features are a very high realm, and I can only do what I can do with my own abilities and experience. More importantly, I hope everyone can contribute their own experiences, we have improved our communication. Based on the above points, I have designed the following framework:

 

Let me give a general idea of this frame chart. First, the overall framework adopts the MVC + Observer model. I believe that experienced peers are not unfamiliar with the two models, so it is easier for them to understand the intention of each other. Second, the interface of the entire framework is displayed in the View class and its front-end, and there are quite a lot of content. I will focus on it when I select an independent framework. However, there are several principles. To improve the reusability of the interface, I have extracted all the interface control elements. In principle, I try not to use the advanced UI provided by Kjava. These control elements include buttons, SoftKey, and ScrollBar. In this way, even if the interface is removed, these controls can still be reused without any impact. All Screen displays are composed of different screens, while View (Canvas) is responsible for switching between different screens, and Screen serves as Layout. Of course, switching between these different modules and message distribution are all problems. I will discuss them in the next topic. Third, adhering to the principle of "highly separated interfaces and data. Therefore, we should not allow any coupling between the interface and data. The View is responsible for the interface, and the Model is responsible for data and processing. The two modules need message transmission. After data processing is complete, you need to give the user a result. The result must be displayed on the interface. Therefore, the Observer mode properly acts as this role. First, Control implements the Observer interface to "encapsulate" screen updates and display to a certain extent ". Second, Control transmits an Observer to the Model through the m_Model variable to "listen" the Model part ". Fourth, the Model is followed by modules such as "network processing", "local file system", and "data storage and processing. Fifth, we can see that there is a ControlQueue queue in the View class, and an EventQueue queue in the Model class. The ControlQueue queue is responsible for maintaining all "Layout" on the View, including those that should be "activated" to process messages. The EventQueue backend queue is responsible for maintaining messages. In most network development, network data packets are transmitted and accepted. The EventQueue is responsible for maintaining the data packet, which is "listened" in the Model thread. Once a data packet arrives, it will analyze the data packet, after analysis, the Observer "listener" is called to reflect the State Changes of the data to the View class.

This part focuses on designing the entire framework process from the high-level. In the following topic, we will apply this pattern to design an application and provide the implementation code of the framework.

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? PostId = 1907976

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.