I created a class in both Java and C # that allows me to execute SQL queries, as an example I have a method called "Delete" that takes several parameters;
public static int Delete(String table, String column, String operand, Object value)
I have a value as an object type, since I can delete strings based on String, Integer or booleans, this means that the method is flexible enough to support different types. Then I add additional " " "characters to the request depending on whether it is a string or not using the instanceof test in Java (or .GetType in C #)
Example:
if (value instanceof String) { System.out.println("It a String"); } else { System.out.println("It not a String"); }
In implementing the rest of the class, I started thinking about myself whether the previously mentioned method is ideal, or should I use additional methods for specific data types, one to place String, another to Integer, etc.
If I started to implement this, this would mean that there will be additional methods in the logic with a minimal difference, however, each method has only one goal, simplifying their passage and documentation. On the other hand, if I save it like this, that is, there is much less code to be created and maintained, it can control any type of Delete instruction (in terms of data types), and there should only be a few if statements to determine the type of object, which was passed through the parameter.
What is the best approach to follow in terms of object oriented / best code practices?
Thanks for the information!