Is simulating structs in Java a good way to go or not?
<p>Once I worked for a big tech company. We programed in Java. Guys there are amazingly smart and they like simulating struct in C/C++ in Java. To make myself clear, they advocate to create classes that act as "data holder":</p>

<pre><code>public class BookInformation {
    public final List&lt;String&gt; authors;
    public final String bookTitle;
    public BookInformation(List&lt;String&gt; authors, String bookTitle) {
        this.authors = authors;
        this.bookTitle = bookTitle;
    }
    @Override
    public String toString() { ... }

    @Override
    public int hashCode() { ... }

    @Override
    public boolean equals(Object obj) { ... }
}
</code></pre>

<p>As we can see, the purpose of this class is simply holding data. Although we violate many enterprise programming rules, such as not exposing class fields directly and defensive copying, this kind of class does gain benefits such as concise coding. Instead of calling getters and setters, we can directly call field names.</p>

<p>The thing that annoys me is that this kind of class is hard to maintain and extend. It is hard to maintain because there is no way to make sure the states of the objects are legal. Business logic may say, a book must have a title and at least one author. But in real world, the objects can have empty title, null title, empty author list or null author list and we simply cannot control it. It is hard to extend. For example, what if the data source is changed to provide first name, last name separately for author name? I have to use two string lists instead of one. Worse, the data structure change affects and interface. Since I don't have a getAuthorNames() interface, I potentially have to change codes in many places.</p>

<p>I have to admit that the above scenarios are not happening. I have to admit that all code uses the class is under the control of the team so interface change doesn't sound that bad as writing for other teams/companies to use. So is it OK to have such coding standard even if we are using Java, a pure OO language, coding in enterprise level?</p>

<p>I know there probably isn't a "right" answer. I'd like to hear personal opinions. Speak loud on behalf of yourself!</p>

<p>EDIT:</p>

<p>OK. I should rephrase the core of my question: is it wise to sacrifice some of the textbook coding rules to gain simplicity? Will the sacrifice bit you later when the code base grows and team grows? Personal opinions matter, especially it is from wise persons and in many cases, there isn't right or wrong questions and we all just follow the convincing opinions. I am sorry Stackoverflow is designed only for right-and-wrong questions. In that case this question should just be closed.</p>
