I’m trying to design a program that uses a third party API. The third party API describes an input with 296 fields, and an output with 179 fields. Obviously I want classes to represent the input and output. Are there any tricks to designing a class with so many fields? Should I have a normal getter and setter for every field?
Note: Because you ask, the API takes a string with all the fields in fixed width format as input, and returns a string with the output also in the fixed width format. It’s very hard to interpret a non-flat structure out of that.
Yikes.
One options is to simply use a Map or similar property holder.
Another option: use a series of nested classes, to add organization (e.g. Order.Person.ContactInfo.Address.ZipCode, rather then just Order.ZipCode). I’m not at all sure I like this one, as it means additional complexity, but without it, finding the particular getter/setter you want (say via autocompletion in an IDE) becomes a nightmare.
Yet another option: if you do create a single class with many properties, consider using the “expression builder” pattern, in which each “setter” returns the object itself, enabling you to chain setters together:
which can create a quicker and more fluent interface then