title: model a generic pojo to use in my classes
body: <p>I'm trying to create an object that works like a generic POJO, since I have to pass it through different objects and I need an interface by which they can access its attributes.</p>
  
  <p>Currently I do it with a base object that has a getField method, where I enter the name of the parameter and I get it through reflection, it's something like this:</p>
  
  <pre><code>public abstract class BasePOJO{
  
      public Object getField(String fieldName){
  
          try {
              return this.getClass().getField(fieldName).get(this);
  
          } catch (NoSuchFieldException ex) {
              Logger.getLogger(BaseRequest.class.getName()).log(Level.SEVERE, null, ex);
          } catch (SecurityException ex) {
              Logger.getLogger(BaseRequest.class.getName()).log(Level.SEVERE, null, ex);
          } catch (IllegalArgumentException ex) {
              Logger.getLogger(BaseRequest.class.getName()).log(Level.SEVERE, null, ex);
          } catch (IllegalAccessException ex) {
              Logger.getLogger(BaseRequest.class.getName()).log(Level.SEVERE, null, ex);
          }
  
          return null;
      }
  }
  </code></pre>
  
  <p>and i use this extending the class like this:</p>
  
  <pre><code>public class CredentialsPOJO extends BasePOJO{
      public String username;
      public String password;
  }
  </code></pre>
  
  <p>and call the attributes like this:</p>
  
  <pre><code>credentialsPojo.getField("username");
  </code></pre>
  
  <p>I have created this quickly, it is horrible but it works. But I want to change it for something more decent to model that object.</p>
  
  <p>También he creado el siguiente:</p>
  
  <pre><code>public class BasePOJO{
  
      private Map&lt;String, Object&gt; parameters = new HashMap&lt;&gt;();
  
  
      public void addParameter(String paramName, Object value){
          parameters.put(paramName, value);
      }
  
      public Object getParameter(String paramName){
          return parameters.get(paramName);
      }
  }
  </code></pre>
  
  <p>I like this object much more, its more OO solution, the problem with this is that it only returns one Object type</p>
  
  <p>The idea is that the objects that use this POJO can access their attributes in a common way.
  If there is a design pattern that solves this problem much better, so I can implement it.</p>