Wednesday, February 4, 2009

Today I have some specific things to share with all of you... As you all came to know from the title of this article that we are going to discuss MVC approach in J2ME. Earlier I used modular approach to develop mobile application, but now I am exploring more on MVC approach in J2ME and I came to know it is really helpful to develop the secure and modular application. Some of you are well aware of this approach and mostly used in your projects. But some of you may be yet not used such kind of approach in your projects then this article may help all of you. I'll try my best to make you understand this approach using J2ME.

For example suppose we have simple application in which user can login and after login user can access some kind of information. Then first of all we can design our application in such a way that data of one class will not exposed to other classes. Suppose all of UI classes will have access using one single class, I name it UIController you can name it as per your requirement. Now all other classes like ModelFacade, & ConnectionManager will interact to LoginUI using UIController and no method of RMS and ConnectionManager will exposed to LoginUI. UIController have one method named it as showLoginUI(), which will take care to display Login screen for application.

Whereas ModelFacade is a class that have single point contact between RMS Class and other classes, so that no stored data will exposed to other classes (Other classes don't have any idea about the content). In same manner ConnectionManager class will manage only HTTP and HTTPS connections and will have logic to connect with server.

Only methods have public access in any class and if you want to use any variable in any other class, then use getter/setter method for that variable.

If you design your application in such a way then there is no security loophole. Try to follow this approach, it really helps you while developing application and also help you in real time testing.

To optimize your application you must follow the Java coding standards, also don't create too much objects because they will cause memory loss. If reference is already present then use that don't create new. For eg.

If ( exampleObj == null ) {

createObject();

}

else {

//do something..

}

If you are using images in your application then used well optimized images.. consult with graphics team. Avoid multi - dimensional arrays in J2ME. Always use pre - computing. Avoid for loop statements if possible, use switch cases and if statements or you may use only those statement in loop which require repeated execution(for loop tightening).

As we know that Java handle garbage collection itself, but while exception occurred and screen transition is there then call System.gc() explicitly. It'll also help you to reduce memory usage by application.

I hope this article will help you. If you have any suggestions and comments please let me know.