Refactoring-the same way to operate on different objects

description

  • trouble boss to point out how to reconstruct the operations of different objects with the same method?
  • At the bottom of
  • is the code. The save methods here are all the same operation. The object is used as a reference here. I just want to ask if this can be refactored?
  • if it were me. I guess I will take the value myself, pass the input value, and then return a path and operate it alone, but I think I can use the object directly here, but I haven"t found any relevant information. Can you give me some advice?
public class ObjectA {
    public save (AA aa) {
        //  aa get , , ,  set  aa
    }
    public static class AA {
        private String img;
        // ... 
        // ... set get 
    }
}
public class ObjectB {
    public save (BB bb) {
        //  bb get , , ,  set  bb
    }
    public static class BB {
        private String img;
        // ... 
        // ... set get 
    }
}

clipboard.png

judge by instanceof. And then take out the data. Then execute the public method
directly generic and you are done

Menu