January 2012
Intermediate to advanced
282 pages
7h 4m
English
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 ...
Read now
Unlock full access