Friday, January 2, 2009

Mutablity


private MutableLocation loc = new MutableLocation();
public Location getLocation() {
return loc;
}

Internally, you store a mutable object, but return it typed as a simple interface when you want to allow only read-only access.This is done to preserve encapsulation and prevents the location fields from being modified by external code.

No comments: