title: Vaadin: Design patterns
body: <p>I am currently working on three Vaadin applications and I really feel like I miss something. I used to work with Spring MVC before, where architecture is clear and decoupled, you inject services to controllers and don't couple controller to UI and so on.</p>
  
  <p>Now in Vaadin that's different story. So if there are any Vaadin specialists out there, let me ask you few questions:</p>
  
  <p><strong>Question 1:</strong></p>
  
  <ul>
  <li>Is it OK to inject services (or DAOs) directly to UI components?</li>
  <li><strong><em>Example</em></strong>: Component responsible for showing contacts in email application (ContactWidget, based on the VerticalLayout with Links) needs to display contacts. Is it OK to inject contactRepository directly to this UI element?</li>
  </ul>
  
  <p><strong>Question 2:</strong></p>
  
  <ul>
  <li>Reference to the main application is being passed to the HUGE amount of UI componenets, because lot of UI components need to access some global data or invoke global methods on main application class</li>
  <li><strong><em>Example</em></strong>: Popup component  has Button that opens new Window, which should be child of the main window in application. Therefore popup component must have reference to main application.</li>
  </ul>
  
  <p><strong>Question 3:</strong></p>
  
  <ul>
  <li>Dependencies between UI components can get pretty wild. Probably nothing much to do here, but sometimes it doesn't feel like that this window depends on this list which depends on that popup ... you get the idea, it looks tightly coupled to me</li>
  </ul>
  
  <p>I'd like to learn as much as possible about good design with Vaadin before my code turns to <strong><em>Spaghetti</em></strong>, so any suggestions, experience and best practices would be appreciated. </p>