title: How to make code dynamic for similar kind of blocks
body: <p>I am creating my web page with vaadin where I need to create same kind of blocks for different type for example need to show blocks having car details, so only car name would be different but the block design would be same with same label but different labels. I want to write generic code so that i can expand it for any car name, without adding it manually.</p>
  <p>Attaching the code snippet which i am using where i am repeating my code for different type. Want to implement it dynamically.</p>
  <pre><code>    private Grid&lt;PresentableGenerateInputHeaders&gt; winTSHeaderColumnsGrid;
      private Grid&lt;PresentableGenerateInputHeaders&gt; fRHeaderColumnsGrid;
      private ListDataProvider&lt;PresentableGenerateInputHeaders&gt; listDataProvider;
      private List&lt;PresentableGenerateInputHeaders&gt; presentableGenerateInputHeaders = new ArrayList&lt;&gt;();
  
  private void initWinTsGrid() {
      
              listDataProvider = new ListDataProvider&lt;&gt;(presentableGenerateInputHeaders);
              winTSHeaderColumnsGrid = new Grid&lt;PresentableGenerateInputHeaders&gt;(PresentableGenerateInputHeaders.class);
              winTSHeaderColumnsGrid.setDataProvider(listDataProvider);
              winTSHeaderColumnsGrid.setCaption(i18n.get(&quot;view.ruleDetails.general.csvHeaderColumns&quot;));
              winTSHeaderColumnsGrid.setStyleName(&quot;a-units&quot;);
              winTSHeaderColumnsGrid.setWidth(&quot;450px&quot;);
              winTSHeaderColumnsGrid.setItems(addGridValues(DataSource.WIN_TS, winTSHeaderColumnsGrid));
              winTSHeaderColumnsGrid.getEditor().setEnabled(true);
              winTSHeaderColumnsGrid.setColumnOrder(&quot;header&quot;, &quot;count&quot;);
              winTSHeaderColumnsGrid.sort(&quot;header&quot;);
              winTSHeaderColumnsGrid.getEditor().addSaveListener((EditorSaveEvent&lt;PresentableGenerateInputHeaders&gt; event) -&gt; {
                  event.getGrid().select(event.getBean());
                  selectedGapFillingCountWINTS.add(event.getBean());
              });
          }
      
          private void initFRGrid() {
      
              listDataProvider = new ListDataProvider&lt;&gt;(presentableGenerateInputHeaders);
              fRHeaderColumnsGrid = new Grid&lt;PresentableGenerateInputHeaders&gt;(PresentableGenerateInputHeaders.class);
              fRHeaderColumnsGrid.setDataProvider(listDataProvider);
              fRHeaderColumnsGrid.setCaption(i18n.get(&quot;view.ruleDetails.general.csvHeaderColumns&quot;));
              fRHeaderColumnsGrid.setStyleName(&quot;a-units&quot;);
              fRHeaderColumnsGrid.setWidth(&quot;450px&quot;);
              fRHeaderColumnsGrid.setItems(addGridValues(DataSource.FR, fRHeaderColumnsGrid));
              fRHeaderColumnsGrid.getEditor().setEnabled(true);
              fRHeaderColumnsGrid.setColumnOrder(&quot;header&quot;, &quot;count&quot;);
              fRHeaderColumnsGrid.sort(&quot;header&quot;);
              fRHeaderColumnsGrid.getEditor().addSaveListener((EditorSaveEvent&lt;PresentableGenerateInputHeaders&gt; event) -&gt; {
                  event.getGrid().select(event.getBean());
                  selectedGapFillingCountFR.add(event.getBean());
              });
          }
  </code></pre>