0

I have a philosophical problem in android, to solve it I have been searching and reading what I have found before asking but none of them has solved my problem, so I'll try to explain it.

I have one android app where I have a database, trying to apply OOP I have created an interface, an abstract class and a class, so that I can use various types of DBs just by changing the reference of the instanced class.

I would also like to maintain this code as clean as possible so that it can be used in any new program that I develop, if possible I always prefer to write code that can be used in any app just by including the files.

Saying so my problem is that I don't know where to put the constant strings of the DB (table names, column names...), a DB that is specific for this app. Since the DB is specific for this app I discard putting them into the interface, don't want to inherit the strings of all the DBs that use this interface into each app. I have also seen that there are other possibilities:

-Interface just to hold the constants, but it's said to be a bad practice

-Class just to hold all the global variables, also a bad practice according to what I have read.

From my point of view, the best place for the declaration of these constants is the interface of the DB, since it's accessible for all the classes that need to use the DB and is more logical. I have come to 2 solutions but I'm open to more solutions:

1.-Creating a copy of the DB interface file for each app, so that I have:

-Clean and common DB interface.

-A modified copy of the original DB Interface including the DB names of one app, this file is exclusive for the app and it must be copied into the directory of the app.

The abstract class and the class would remain the same and common for all the projects.

2.-Extending an interface into the DB interface so that it has access to the Names of the DB, each app should have an exclusive interface with the names of the DB.

I would like to know which one would be the best solution according to your experince or if there is another solution that could make the DB interface common and usable for any app without inheriting code from other apps.

Hope I made my point.

Thank you.

user1368116
  • 121
  • 6

1 Answers1

0

I don't think it is bad practice for your class to have say:

public final static String TABLENAME = "TABLENAME";

on your class, if client's of the class need uniform values.

MikeHelland
  • 1,151
  • 1
  • 7
  • 17
  • 1
    In which class should i put this string? It doesn't have sense to put it in the DB class and don't want to put it on a class created just to hold variables([globar variables in java](http://stackoverflow.com/questions/4646577/global-variables-in-java)). – user1368116 Jan 20 '14 at 19:36