Note that there are some explanatory texts on larger screens.

plurals
  1. POJava MVC - Doesn't feel like I get it
    text
    copied!<p>As a beginner in programming it always bugs me when I run into a walls. Currently one of the wall are co-depending objects. </p> <p>As you can see in my question history I'm currently working on a blackberry application, in which I implemented something I call the MVC Pattern, but it isn't exactly what I think it's meant to be.</p> <p>You see, a novice programmer you look on abstracts like this graphic and you get the idea behind it. But implementing it is another thing.</p> <p><a href="http://www.ibm.com/developerworks/wireless/library/wi-arch6/theoretical.gif" rel="nofollow noreferrer">alt text http://www.ibm.com/developerworks/wireless/library/wi-arch6/theoretical.gif</a></p> <p>Please, don't stop reading :) I'm showing you some of me code, which contains some blackberry specific stuff, but you should see what I'm doing.</p> <p><strong>Main Entry Point for my Application</strong> </p> <pre><code>public class ContactManager extends UiApplication { private static ContactManagerMainScreenModel MainScreenModel = new ContactManagerMainScreenModel(); private static ContactManagerMainScreen MainScreenView = null; public static void main(String[] args) { new ContactManager().enterEventDispatcher(); } public ContactManager() { MainScreenView = new ContactManagerMainScreen(MainScreenModel); // Displays the Splashscreen then opens the Mainscreen new SplashScreen(UiApplication.getUiApplication(), MainScreenView); } } </code></pre> <p><strong>The Mainscreen Model</strong> </p> <pre><code>public class ContactManagerMainScreenModel { ContactManagerMainScreen v; // Loading Local Storage LocalContactStorage LocalContactStorage = new LocalContactStorage(); // Define Data List private Vector vContacts_Favorites; public void register(ContactManagerMainScreen v) { this.v = v; } // Retrieve Favorite Contacts from Persistant Storage public Vector getFavoriteContactsFromLocalStorage() { vContacts_Favorites = LocalContactStorage.getFavoriteContactsFromLocalStorage(); return vContacts_Favorites; } // Put Retrieve Favorite Contacts from Persistant Storage public void saveFavoriteContactsToLocalStorage() { LocalContactStorage.saveFavoriteContactsToLocalStorage(vContacts_Favorites); } } </code></pre> <p><strong>The MainScreenController</strong></p> <pre><code>public class ContactManagerMainScreenController { private ContactManagerMainScreenModel _model = null; private ContactManagerMainScreen _view = null; public ContactManagerMainScreenController(ContactManagerMainScreen view, ContactManagerMainScreenModel model) { this._model = model; this._view = view; } public void HideFavoriteList() { if( this._view._ContactList.getManager() != null) { this._view._ContactList.getManager().delete(this._view._ContactList); } else { this._view._bottom_box.add(this._view._ContactList); } } } </code></pre> <p>Still there? Okay ... </p> <p>My Problem here is, that I want to use the controller to change UI Elements, like Displaying a PopUp Box, hide someting or other things.</p> <p>But all these UI Elements are defined in the View (here ContactManagerMainScreen) so have to give to the Controller a reference to the View. Which leads to my co-depending objects misery.</p> <p>I cannot create the controller before the view is declared. Without the requirement to allow the controller to change UIElements, it would be no problem (as shown in the Graphics).</p> <p>What I'm doing now is that the View creates the Controller </p> <pre><code>controller = new ContactManagerMainScreenController(this , model); </code></pre> <p>Does that makes sense? I want to understand the pattern, so call my code trash or anything you like :) I just want to learn something.</p> <p>P.S. I beg your pardon for my bad english :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload