I created a builder - following from Joshua Block 2nd Ed Item 2 - to construct an object representation of a cell (to be rendered in say a html table through jsp later). I thought that this would be a good way to handle many optional parameters, and would readily allow for additional fields to be added to object later.
Now I am designing a class to read an xml file and to construct the cell objects.
Is there an elegant way to do this?
Currently I am thinking that I will need to use something along these line
Where if the reader does not find an attribute a null is passed to the builder. This seems a little clunky.
This is my first serious Java program, so I may be on the wrong track here.
Any help would be great.
Sample XML file snippet (having trouble rendering this)
I have solved my own problem now, and thought I would let this thread know so as to close it.
Anyway, I ditched the builder pattern - even though I though it very beautiful - and instead passed a HashMap of attributes read by my XML reader to the constructor who then checked the HashMap for passed through values and if it didn't find a particular attribute in the HashMap the constructor then assigned a default value in the object.
I used a developed enum class, with a "fromString" method, to provide a level of "type" safety for all of this.