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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.