how can we achieve the MVC pattern in Mobile Application so how can we do it .we can use the MVC pattern in mobile application when we have working on large project that have more than 10 screens .There are ways to how create the screen
1) Create the separate MIdlet for each screen .
2) Create the single Midlet & define all the function that create the screens & perform its task in the single Midlet & display.setCurrent call each method when they want to show the particular screen .
this technique is good & work well faster than option 1 but there is some problem with this approach .Let we discuss
*)My code become too complex that hard to manage .
*)If the requirement change so its hard to me to change it .
*)It hard to manage the Objects .
so What's now we should implement the MVC pattern in this project .how?
Let see this.
The scenario is we have Single Midlet that have the Display Object to show the screen on the Midlet.For make the Midlet to act ascontroller it should be singleton but we cannot do it because the constructor of the Midlet always be public.
so what we do
We create the static function that return the static controller Object .In the constructor we call the super() method & set the staticControllerObject=this;
Now that's make our controller to act as singleton singleton
we have a classes each screen has its own class in which they all inherit with interface that have the hashtable with its getter & setter & that interface implement another interface that have the function that return Displayable Object .
so all the classes that extend the first interface should implement the function that return Displayable Object so all the classes should implement it .
If we want send data between screen we use get & set hashtable method to send & receive data from the screen.
Now back to our controller
All the classes want to show will call the controller function to get the controller object then by using this object we call the function that get the class name & hashtable Object. Get the Object of the class by using the for.ClassName (that we discuss in previous post) after getting the class object we call the set method of hashtable & pass the hashtable to the argument then call the function that return the Displayable Object so that the controller should show that object.
Now what we achieve
*)Our all screens were separate all the screens were manage there commands & if they to go to next screen they just call the controller method by passing the screen Class name & hashtable to send the data to next screen then Rover will transfer it to the next screen.
*)Our Code will easy to manage & we would remove the dependency of screen to the other .
*)The Controller Midlet will only act as a controller it not listening any command
That's all hope its work for you But its work god for me :)