Is it customary to write Java domain objects / data transfer objects with public member variables on mobile platforms?
- by Sean Mickey
We performed a code review recently of mobile application Java code that was developed by an outside contractor and noticed that all of the domain objects / data transfer objects are written in this style:
public class Category {
public String name;
public int id;
public String description;
public int parentId;
}
public class EmergencyContact {
public long id;
public RelationshipType relationshipType;
public String medicalProviderType;
public Contact contact;
public String otherPhone;
public String notes;
public PersonName personName;
}
Of course, these members are then accessed directly everywhere else in the code. When we asked about this, the developers told us that this is a customary performance enhancement design pattern that is used on mobile platforms, because mobile devices are resource-limited environments. It doesn't seem to make sense; accessing private members via public getters/setters doesn't seem like it could add much overhead. And the added benefits of encapsulation seem to outweigh the benefits of this coding style.
Is this generally true? Is this something that is normally done on mobile platforms for the reasons given above? All feedback welcome and appreciated -