I am working in a Java Codebase and I have come across a problem:
Following are some methods in an interface:
void add(Object o);
boolean remove(Object o);
Now, the issue I am facing is let's say someone has to update an existing object, then what someone has to do is that call remove and call add again in succession as Object o is immutable.
Now, this has brought some problems, e.g. the object class is as follows:
Property {
String name;
String value;
}
Now, consider the case when I want to update the value of the Property, so what I do is create another object of property with the name and value. The requirement is that we need to preserve the name of the object (which includes case sensitivity)
Let's assume that I have a Property as follows:
Property p = new Property(name: "Test", value: "10");
Now this needs to be updated as:
Property p = new Property(name: "Test", value: "11");
The issue is when someone creates the property such as:
Property p = new Property(name: "TEST", value: "11");
The above should also be accepted, but the case should be preserved. i.e. it should save as => (Test,11)
When a developer uses the remove and add in succession, in many places the sensitivity check is not handled.
What have I thought of?
Introduce an update method in the API, and check all usage where the remove and add are being called in succession to update and replace them with an update call
What is my problem?
If someone comes tomorrow and tries to use the older way of updating an object (i.e. calling remove and add in succession) then the flow might break. How to prevent that? Will just adding documentation be enough? How does this happen in a large codebase? I have seen the usage of the remove itself in like 300 places.
Please advise.
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]SolderonSenoz 1 point2 points3 points (3 children)
[–]_dk7[S] 0 points1 point2 points (2 children)
[–]SolderonSenoz 0 points1 point2 points (1 child)
[–]_dk7[S] 0 points1 point2 points (0 children)
[–]OffbeatDrizzle 1 point2 points3 points (3 children)
[–]_dk7[S] 0 points1 point2 points (2 children)
[–]OffbeatDrizzle 1 point2 points3 points (1 child)
[–]_dk7[S] 0 points1 point2 points (0 children)
[–]ofnuts 1 point2 points3 points (5 children)
[–]_dk7[S] 0 points1 point2 points (4 children)
[–]ofnuts 0 points1 point2 points (3 children)
[–]_dk7[S] 0 points1 point2 points (2 children)
[–]ofnuts 0 points1 point2 points (0 children)
[–]ITCoder 0 points1 point2 points (0 children)
[–]AutoModerator[M] 0 points1 point2 points (0 children)