title: Enum design with lots of fields
body: <p>I want to implement a EAN128 barcode parser. In short, EAN128 barcode is built by one or more fields, each one composed by a string identifier and a value. There is a hundred different identifiers and each value has fix or variable length (numeric or alphanumeric) depends on the identifier. Variable length value ends with special char named FNC1.<br>
  I want get all identifiers and its value from a barcode.<br>
  My design is based in an enumeration with one field for each code identifier.</p>
  
  <pre><code>public enum IDENT_EAN128 {
    // Identifier 8003 that has a value composed by 14 numeric chars and 1 to 20 alphanumeric chars
    IDENT_8003 ("8003", FixedParser(14, NUMERIC), VariableParser(20, ALPHANUMERIC)),
    IDENT_00   ("00", FixedParser(18, NUMERIC)),
  
    .... // hundred identifiers
  
    private IDENT_EAN128 (String code, Parser... parsers ) {
       ...
    }
  
    public static IDENT_EAN128 search (String code) {
      // loop IDENT_EAN128.values() to search code identifier
    }
  }
  
  public class Main {
    public static void test () {
      String id1 = "8003";
      String field1 = "12345678901234";
      String field2 = "12345" + FNC1;
  
      String id2 = "00";
      String field3 = "123456789012345678";
  
      String barcode = id1 + field1 + field2 + id2 + field3;
      for (int posBarcode; posBarcode &lt; barcode.length(); posBarcode++) { // loop chars of barcode
        char[] buffer ...
        IDENT_EAN128 idEAN = IDENT_EAN128.search(buffer)
        if (idEAN != null) {
          // loop Parsers for get identifier value
          // move posBarcode to the first barcode position of next identifier
        }
        ....
      }
    }
  }
  </code></pre>
  
  <p>Parsers return identifier value, validate its length and that the value has the correct char type (numeric or alphanumeric).
  The problem with this design is that when is called first time, it creates hundreds of new objects (each identifier and its parsers). Most times barcode only have 3 or 4 identifiers. So, I think it's a wate of time and memory. I have search about "lazy inizialitation" design for parsers, but I haven't found something that correspond with my problem. Is there a better design? or my concern is for nothing.</p>
  
  <p>Thanks</p>