This is my scenario, I have this interface:
public interface hitTheDataBase
{
public void insertMe(String [] values);
public void modifyMe(String [] values);
public DataTable selectMe();
}
And I have these two classes that implement the interface:
public Class hitSqlServer implements hitTheDatabase
{
public void insertMe(String [] values)
{
executes insert into table_in_sqlServerBD (col1, col2) values(values[0], values[1])
}
public void modifyMe(String [] values)
{
executes update table_in_sqlServerBD set col1 = values[0], col2 = values[1] where rowid = values[3]
}
public DataTable selectMe()
{
executes select col1, col2 from table_in_sqlServerBD
}
}
public Class hitSqLite implements hitTheDatabase
{
public void insertMe(String [] values)
{
executes insert into table_in_sqLite (col1, col2) values(values[0], values[1])
}
public void modifyMe(String [] values)
{
executes update table_in_sqlLite set col1 = values[0], col2 = values[1] where rowid = values[3]
}
public DataTable selectMe()
{
executes select col1, col2 from table_in_sqLite
}
}
This is part of a beta app actually running in testing and in production(!) environments, but it will be updated regularity because of bug fixes no related with the database operations. The updates are simply made via uninstall and re-install.
Now, I have a new requirement for a very specific corner situation that will need a new column "col3" be added to the table, and I'll have to insert, select and update values in that column too. The problem is that I do not want to break backward compatibility with existing databases where the software is already running.
I was thinking about coding a third class that implements HitTheDataBase interface, a helper class to check if "col3" exists, and making something like:
hitTheDataBase hitMe = !helperclass.col3Exists() ? new hitSqlServer() : new hitSqlServerWithCol3();
Is this a good approach? It looks good to me, except because I will need to modify the code in the classes that use the ones that "hit the database". Also I'll have to constantly check if the value of col3 exists to show it in the GUI and let the user modify it.