Is it good style that calling setters follow the same order as XSD elements?

by Ivan Milosavljević   Last Updated December 07, 2017 11:05 AM

In the project I work on we use XSD to generate some classes. XSD determines the order of elements, similar to this snippet:

<xs:element name="Customer_ID" type="com:Text6"/>
<xs:element name="Customer_Desc" type="com:Text150"/>
<xs:element name="Customer_Name" type="com:Text50"/>
<xs:element name="Institution" type="com:Text150" minOccurs="0"/>
<xs:element name="Scheme" type="com:Text50"/>
<xs:element name="Country" type="com:Country"/>

One colleague created some tests in which he sets object fields in different order comparing to the order in XSD, for example:


Furthermore, he uses different order in different tests. I argued that we should stick to the same order in code as it is in XSD because that way it's easier to read or change code/XSD. He thinks it's nitpicking because, at the end, object will have its fields initialized anyway.

I'd like to hear your thoughts - is this really nitpicking from my side or not?

Answers 1

The fact that you are using XSD is not important. You are creating Java classes and those don't care the order (well, unless there is some dependency that should be dealt with in the constructor or a builder, rather than through setters). Keeping them in order because of the XSD can end being a maintenance nightmare, as any change on the class/schema could mean reordering every single place where you use your setters

Miyamoto Akira
Miyamoto Akira
December 07, 2017 10:53 AM

Related Questions

Getters with data conversion in Java VOs

Updated August 22, 2015 19:02 PM

Constant value vs literal value - Which one?

Updated June 25, 2018 13:05 PM