java – Should a Move and a Tracker be separate classes to maintain SRP?


I am practicing a Java code to better understand the principle of sole responsibility. Currently, I am working with a network of data structures, where each structure implements an interface called Location.

public interface Location {

    void removeObject(Object o);
    void addObject(Object o);
}

Different locations store and retrieve objects differently, so everyone needs their own method to add / delete them. The goal is to be able to freely move objects between locations and find where the objects are currently. I have two classes called to move the Objects, one to make the actual movement of the Objects (the Move) and another to keep track of where the Objects are so that they can be retrieved for the Move class (the Tracker).

public class Database {

private Mover mover;
private Tracker tracker;

//Contains methods for moving specific Objects to specific Locations.

}

public class Mover {

void moveObject(Object o, Location a, Location b)
{
  a.removeObject(o);
  b.addObject(o);
}

}

public class Tracker {

Map> trackerMap;

void updateTracker(Object o, Location a, Location b)
{
    trackerMap.remove(a);
    trackerMap.put(b, o);
}

Object lookupObject(Location l, Object o)
{
    List objects = trackerMap.get(l);
    return objects.get(o);
}

}

However, I have some concerns about this design. Because Move and Tracker have been divided into separate classes, data structures are essentially stored twice. Once for the Tracker map and once for the actual data structures, the Move is modifying. It seems prone to errors. If the two were out of sync for any reason, the Move could end up trying to move things that do not exist, and the Tracker may be unable to find them. I still have the feeling that the Move should be directly modifying the Tracker map when moving Objects, to ensure they remain synchronized. However, if the Move begins to modify the Tracker, then the Tracker does not need to be its own class. And combining the two, from what I understand, would violate the SRP.

How can I improve the design of this database while maintaining the SRP?