I have a GWT web application that uses the URL to navigate and the MVP pattern. For each URL I have a presenter to be called. I have about 20 differents presenters, and to decide which one to call, I use conditions like
if (view.equals("vue1")){ presenter = new presenter1(); }else if(view.equals("vue2")){ presenter = new presenter2(); }else if(view.equals("vue3") || vue.equals("vue4") || vue.equals("vue5")){ presenter = new presenter345(); } ...
I tried another alternative, which is to load a HashMap at the starting of the application. The map contains the view as a key and the Presenter as the value. But it get complicated because I often have multiple keys (views) pointing to the same Presenter. So for the last condition in my example above, I will do something like this :
map.put("vue3",new Presenter345); map.put("vue4",new Presenter345); map.put("vue5",new Presenter345);
Questions :
1- Which one is efficient, knowing that the code is on the client side (JavaScript) ?
2- Is there another alternative ?