Laying Out Your Data

Once again, the principle of encapsulation will be broken. Let's assume your application needs to store records of some sort, and each record contains two fields: an id and a value. A very object-oriented approach is to define a Record class, as shown in Listing 4–12.

Listing 4–12. Record Class

public class Record {     private final short id;     private final short value;     // and possibly more          public Record(short id, short value) {         this.id = id;         this.value = value;     }     public final short getId() {         return id;     }     public final short getValue() {         return value;     }     public void doSomething() {         // do something here     } }

Now that the Record class is ...

Get Pro Android Apps Performance Optimization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.