Hi Thomas, thanks for replying... The style thing is I guess questionable, but the basic problem with the pattern as presented which favors the Has* interfaces, etc. I think is still a design issue to consider. Another post shortly after mine basically issued the same question http://groups.google.com/group/google-web-toolkit/browse_thread/thread/19b1600e34ca8f99/b6671eb90041154c#b6671eb90041154c
If it isn't addStyle( ) (your point is well taken)...it will be something else the presenter wants to manipulate on the view's widget. I guess my point is that if you have a view that is something beyond most blog/tutorial posts, it just seems to me that not returning the actual widget either makes the interface blow up, or you end up doing lots of nasty casting. My basic question is: why not just return TextBox if that is what is in your view? The coupling is between 2 classes: view and presenter. If you later change TextBox to SuperWidgetTextBox, you can re-factor it in your IDE in 5 seconds and be done with it. Am I missing something? Regards, Davis On Tue, Aug 18, 2009 at 7:05 PM, Thomas Broyer<[email protected]> wrote: > > > > On 18 août, 18:40, davis <[email protected]> wrote: >> I'm trying to implement a version of MVP as discussed at Google I/O >> talk: >> >> http://code.google.com/events/io/sessions/GoogleWebToolkitBestPractic... >> >> So, one can have a presenter class that defines an internal interface, >> and I see it typically done like this: >> >> class PhoneEditor { >> interface Display { >> HasClickHandlers getSaveButton(); >> ... >> } >> >> It seems to me that this tends to get a bit unwieldly in practice. >> For example, I have an account registration page. Let's say it >> contains a TextBox for username and a PasswordTextBox for password. >> >> Here are some things I'd like to do to that box in my presenter: >> >> get the value, so I could have >> >> interface Display { >> HasValue<String> getUsername(); >> HasValue<String> getPassword(); >> } >> >> But I also have validation code in my presenter, which will validate >> the content of the fields, and do things like set style errors. >> >> #addStyleName( ) is defined on UIObject, so I'm kinda out of luck with >> that interface unless I define something like: >> >> interface Display { >> HasValue<String> getUsername(); >> HasValue<String> getPassword(); >> UIObject getUsernameBox(); >> UIObject getPasswordBox(); >> } >> >> but that is kind of a ridiculous and redundant interface. So, really, >> my question is what is so wrong with: >> >> interface Display { >> TextBoxBase getUsernameBox(); >> TextBoxBase getPasswordBox(); >> } >> >> I get the fact that if you can use the Has* interfaces, it helps >> decouple the presenter from the view more by allowing the view to >> change to other UI widgets later on, but I find it far too limiting in >> being able to manipulate the view objects without either having large, >> redundant interfaces or else doing lots of unsafe casting. >> >> Has anyone else encountered this conundrum, and how are they >> approaching it? I'm inclined to make my Display interfaces explicit. > > Your presenter shouldn't deal with "styles", it should instead tell > the view to show error near/on the "username" and/or password (or > nowhere particularly). It's the responsibility of the view to > determine (be implemented that way) if it should set a red background > and/or red border on the textbox, and/or show an icon next to the box, > and/or show an "error summary" above or below the boxes, etc. > > > -- Zeno Consulting, Inc. home: http://www.zenoconsulting.biz blog: http://zenoconsulting.wikidot.com p: 248.894.4922 f: 313.884.2977 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
