I try to understand where good contracts end and paranoia begins. Actually, I just don’t know what a good developer should take care of and what he should forget about :)
Let's say I have a class that contains values (s) such as java.lang.Integer. Its instances are aggregated by other objects (MappedObjects), (one-to-many or many-to-many) and are often used inside MappedObjects methods. For performance reasons, I also track these relationships in TreeMap (besides, guava MultiMap doesn't matter) to be able to quickly iterate over MappedObjects bound to a certain range of Integer keys. Thus, in order to maintain system integrity, I have to change the MappedObject.bind (Integer integer) method to update my map as follows:
class MappedObject {
public void bind (Integer integer) {
MegaMap.getInstance().remove(fInteger, this);
fInteger = integer;
MegaMap.getInstance().add(fInteger, this);
}
...
private Integer fInteger;
}
MappedObject , , . MappedObject bind() - .