Is it customary to write Java domain objects / data transfer objects with public member variables on mobile platforms?

Posted by Sean Mickey on Programmers See other posts from Programmers or by Sean Mickey
Published on 2012-06-06T06:34:13Z Indexed on 2012/06/06 10:48 UTC
Read the original article Hit count: 321

Filed under:
|
|
|
|

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 -

© Programmers or respective owner

Related posts about java

Related posts about coding-style