Following the documentation on places & activities + MVP, for each page I have to create:
I created an app with basic functionality(5 pages and a navbar) and I already have more than 1500 lines of code and ~40 files. I think this is completely unmaintainable, however I haven't found anything on solving this. There are a couple of frameworks(eg GWTP) which implement MVP but they need the same amount of boilerplate as well.
I could achieve the same functionality in ~200 lines using spring mvc or play.
What am I doing wrong and how would you solve it?
I think this is completely unmaintainable
I do not agree with you. Large number of small files is much better for maintenance than couple large files. I agree that GWT is much more verbose than Spring MVC:
In a case of GWT due to strict nature of Java and statefull view you must do a lot of additional work. It is completely maintenable (if it is done correctly). Main advantage is that you can add unit tests for your presentation layer. Due to this fact it will be more maintenable for long running projects with complex UI, large codebase and big team. If it is not the case for you project (screens are simple and you do not plan to add unit tests for UI layer) then it may be better to:
Two another advantages of interfaces between view and presenters:
What is really annoing with all these files is that it takes much time to setup one activity. To simplify it:
Another source of boilerplate is data binding. Consider using editor framework.
The main benefit of using MVP with GWT, is the ability to unit test your presenters in isolation, using plain JUnit TestCase
, instead relying on the painfully slow GwtTestCase
.
The other benefits, such as mainteinability, can be achieved using simpler project structures like @Maksym Demidas pointed out.
So the real question is if you want/need that degree of testing inside your project, at the cost of the aforementioned boilerplate. Do note that places and activities have nothing to do with MVP: you can use them to achieve MVP but they are simply about navigation and view transitions between places (URL
s).
I'd really suggest you to take a look at the recent Erik Kuefler's Google IO 2013 presentation - Demystifying MVP and EventBus in GWT
. It should help you identifying when to use MVP and when not. Also, take a look the at the open source library he released, specifically to GwtMockito
(i.e., testing widget's logic in plain JUnit TestCase
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With