Application of MVC mode in J2ME project (2)
Author: FavoYang Email:
Favoyang@yahoo.com Welcome to exchange
Keywords: MVC case mode
Summary:
If you want to experiment, you have a little bit of knowledge, the best way is to practice her. Combined with a project called "Note" (Notepad), use the MVC mode to build, and experience the power of MVC and flexible. Note that this article about the use of MVC is no longer used, but uses the boundary class, control class, physical class, and lifecycle class. Regarding the changes in MVC on J2ME, please see this article (1), especially to see my habits, otherwise it is difficult.
This paper attaches great importance to the overall design, there is no too much talk.
I Want a Good Sleep.
Copyright Notice:
This article is also published
Www.j2medev.com and my blog (blog.9cbs.net/alikeboy), if you need to reprint, there are three ways: 1) Contact me and agree; 2) and www.j2medev.com has reprinting article cooperation agreements 3) Aggregate my blog through RSS. In addition, the online reprint requires a full text forwarding (including the statement of the head of the article), do not break chapter.
text:
Note project description
The mobile phone is a truly portable digital terminal, in addition to using the mobile phone, sending information, often letting him help us record textual information. PDA has a large screen and handwritten function, and the memory on the phone is limited, and the content recorded is simple. It can be said that the use of mobile phone record information is a function that is considered to be a series of applications - the mobile phone is used as an information collector anytime. It is not difficult to envision such applications to use a certain market, our Note Notepad project we have chosen today is the original shape of such applications.
Note is a built-in application of many mobile phones, which is generally called notepad or note, which is a very common service. Maybe friends may think that developing an existing program is not challenging. Yes, the most taboo in development is to focus on the wheel, but it can be said to the teaching. After all, a simple prototype will not let us fall into too many details, my main purpose is to introduce you to the application method of MVC mode.
Note provides mobile phone users with a function of recording some short information. Users can add records to open a browsing record, and modify the records already saved on the phone at any time, of course, they can also delete them. Just like the notepad under Windows, only more managed features.
Use case analysis
First imagine who is using this program: mobile phone users. Ok, we will call this participant later for users (USER).
Then I want to do it, what do users use our Note (Chinese we call records)? Obviously, users can add new records, browse the records he added, modify the record he added, and he can delete records. A record should simply include the content of the user's record, recorded or modified, and the most important records.
The general situation developers are very displaced by this textual description, often because developers are accustomed to treating hard PCs, rather than facing customers, collecting this requirement. In fact, textual things are both an overview of the system, and we find the soil of developing elements. Imagine if your software is to be released, you can't organize the language to make the user's proper understanding of the function and use object, how is it.
Demand for refined users (in fact, my teaching needs haha). Obviously, adding records and modification records belong to the editing of the record, is called
Editing record case (
NoteEdit
)All right. The browsing record is also a very obvious use case, it is called
Browse Case (
Notepad
). Delete is a kind of management, called
Management record case (
Notemanager
). At this point, we have discovered and refined three main use cases, not bad, the system is a step in step. Here you remind everyone, this stage is to stand in the customer's point of view (here is the user's point of view), your job is to discover and systematically understand the idea of the customer, do not have to think about any detail at the developer's perspective.
So, Let 'Go.
Editing record case (
NoteEdit
)
Event stream 1:
1) Display the content of the user Note
2) User editing
3) The user gives up the modification, the Note content is constant, normal exit
Event stream 2:
1) Display the content of the user Note
2) User editing
3) User Save, return to the main menu
Event stream 3:
1) Display the content of the user Note
2) User editing
3) User Save AS, prompt to enable users to enter new file names
4) Save, return to the main menu
Browse Case (
Notepad
)
Event stream 1:
1) Display the title of the user, create time, content
2) Users choose to quit, return to the main menu
Event stream 2:
1) Display the title of the user, create time, content
2) Users show editing, steering editing example
Management record case (NoteManager)
Event stream 1:
1) Display the user's Note list
2) User opens the selected note, steering browse example
Event stream 2:
1) Display the user's Note list
2) Users edit the selected Note, steering editing example
Event stream 3:
1) Display the user's Note list
2) Users create new Note, steering editing example
Event stream 4:
1) Display the user's Note list
2) User deletes the selected Note
3) A confirmation prompt
4) User confirmation, delete Note
5) Update display, return to the Note list
Once the three use cases of the use case, it is clear that all iterations should be completed in the first iteration.
Find class (OO analysis)
The first is the entity (entity), only need to extract the name from the event stream to narrow the range.
Note, it is obviously an object.
Content, time (datetime), title, should be Note's elements.
The Note method includes the operation SET / GET for domain members. Since it is to be saved, a serialization reactorization method is required.
The general physical classes are used by a corresponding life cycle class (Lifecycle) for his production, storage, dying, etc., generally independent of such operations, greatly uses the reuse of the entity. However, this stage does not need to analyze him, and it will naturally find it when you draw sequence. It is used to the method of efficient painting diagrams, border classes, and control methods. But we save, everyone only knows that each usage corresponds to a border class.
Design practice
I will give three use cases
Part of the record case (NOTEMANAGER) and
Browse a portion of the NOTEPAD to introduce the detailed design process. Here, we tried to transform from a customer's angle to a developer angle. To face a lot of challenges, it may include some details. It should be learned from the perspective of separation. The essence of MVC is here.
Record case (NOTEMANAGER) event stream 1:
NoteManagerUi does not know the specific organizational form of the Note list, which returns a string [] array for the control class by the preloaded interface GetNotetitlelist to the control class NoteManagerWorkflow.
Similarly, NoteManagerWorkflow needs to be data to be available to the lifecycle NOTELOCATOR, but the NoteManagerWorkflow knows the details of the data. In order to be able to identify data, in addition to returning the information of the recorded Title, it is necessary to return a uniquely identified ID as a method that identifies Note within the entire system. So NoteManagerWorkflow has two domains one is TitleList, one is IDLIST.
Here are a few details:
1) NoteManagerUi, how to communicate, this is not a problem, we have reason to believe that they are closely related.
2) NoteManagerWorkflow How to find Notelocator, in general, NOTELOATOR is single SINGLTON.
3) When NoteManagerui's shownote (index), he calls the NoteManager's shownotedispose (Index), while Shownotedispose will convert this index to ID according to the internal implementation.
Browse (NOTEPAD) event stream 1:
Notepadui To the Control Class, control class NOTE, and NOTEID, but the control class via getNode, which is clearly used here to use inert initialization technology to the lifecycle to Note. After obtaining the reference to the record object, you can easily request data like an entity class.
Experience sharing
Of course, you can start when you have the skeleton, you can start, the advantage of the drawing is to force you to do the interface design between the various components during the design phase. This can effectively reduce the chances of your rework, but often thinks too much in the design phase, such as how NOTELOCATOR communicates with RMS. This is a very bad habit, but it is not easy to correct. Because whether it is a school, or train, etc. is training, repeated training we are sensitive to Coding. We are too dependent on the problem from the perspective of code, which hinders our thinking about the problem from the overall situation and discover more common mode.
If you want to start Coding, don't be fully available at the beginning, the general entity class has strong independence. Can be developed independently, while developing other classes can start from the boundary class, if you want to test one side, you can temporarily use Fade Data (pseudo-support data) by making the control class, lifecycle class. This is greatly reduced. A good way to complex. If you have condition, please make cell test, otherwise the test efficiency is really low. (PS, someone writing the article test under J2ME test, I want to let test automation)
Inert initialization is the most frequent technology I use, I think it can greatly reduce the degree of code confusion.
UML of the entire system
Some people say they don't understand UML, but if I give me such a big code, I will definitely understand. UML, it is possible to understand :)
Screen snapshot
Starting screen: (management case)
New screen: (editing case)
Press Save, enter the title name
Update display:
Choose your favorite browsing, such as the title is EASY record: (View case)
Screen navigation:
Variety
Some friends are not willing to open their own code, but for Java, it is too easy to compile. You don't have any secrets. Compared with the design, the code is a very fine thing. If someone is willing to modify the code for you, if you are fully improved, it is not found to be in the lantern. I have developed with Eclipse, which is the crystallization of open source. Of course this is the additional code of the article. Real project If the open source must be done under GPL. No one wants to appear in DivX again. Reprinted friends, then say a free of charge not only equal to NOT COPYRIGHT.
9CBS friends, because I don't know how to get an attachment outside the image, you have to start with reference.
Www.j2medev.com.