On Mon, Jan 24, 2011 at 1:35 AM, sunny...@gmail.com <sunny...@gmail.com> wrote:
> Hi all, I've been getting my head around DI/gin/guice lately....
>
> Here is a really simple widget:
>
> public class UserForm extends DynamicForm implements UserFormInterface
> {
>
>        private TextItem txtUsername;
>        private TextItem txtFirstname;
>        private TextItem txtSurname;
>
>        @Inject
>        private UserForm(TextItem txtUsername, TextItem txtFirstname,
> TextItem txtSurname) {
>
>                this.txtUsername = txtUsername;
>                this.txtFirstname = txtFirstname;
>                this.txtSurname = txtSurname;
>
>                this.txtUsername.setTitle("Username");
>                this.txtFirstname.setTitle("Firstname");
>                this.txtSurname.setTitle("Surname");
>
>                this.setShowEdges(true);
>                this.setFields(this.txtUsername, this.txtFirstname,
> this.txtSurname);
>        }
>
>        @Override
>        public String getUsername() {
>                return txtUsername.getValueAsString();
>        }
>
>        @Override
>        public String getFirstname() {
>                return txtFirstname.getValueAsString();
>        }
>
>        @Override
>        public String getSurname() {
>                return txtSurname.getValueAsString();
>        }
>
> }
>
> public interface UserFormInterface {
>        String getUsername();
>        String getFirstname();
>        String getSurname();
>        void draw();
> }
>
> ginjector:
> @GinModules(MyWidgetClientModule.class)
> public interface MyWidgetGinjector extends Ginjector {
>        UserFormInterface getUserForm();
> }
>
> And module:
> public class MyWidgetClientModule extends AbstractGinModule {
>        @Override
>        protected void configure() {
>
> bind(UserFormInterface.class).to(UserForm.class).in(Singleton.class);
>        }
> }
>
>
>
> In such simple cases (eg, when coding a composite widget), is there
> any point in using GIN? Where would one draw the line and say 'oh I
> really should've done it the other way instead?'

It's a matter of taste.
My recommendation: If you have a small and tiny app that you don't
want to test and extend: Don't use Gin.
All other cases: Use Gin. It makes your code structure more modular,
maintainable and more testable.

At the beginning dependency injection might sound like a strange and
complex thing. But it is not. It's simple and straight forward once
you got the concepts.

Cheers,

Raphael

>
> --
> You received this message because you are subscribed to the Google Groups 
> "Google Web Toolkit" group.
> To post to this group, send email to google-web-toolkit@googlegroups.com.
> To unsubscribe from this group, send email to 
> google-web-toolkit+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

  • Simple GIN sunny...@gmail.com
    • Re: Simple GIN Raphael André Bauer

Reply via email to