I have a generic question and I don't understand how create what I want. I writing a basic program they can access to one database an do some SQL request, etc. But at the moment I have one big class with all SQL for all the tables from the database. And I want slipt this class in different classes for make the code more easy to read and implement stuff. I think the best solution is create one subclass for each table on the database and on for this class put all the methods related on this class. But later I don't understand how I can call this methods from the class. Because for access to the database I create an object DataBase on the main application and if I want call a method just I do a database.methodIWant().
At the moment I have:
DataBase(this class have all the methods for the databases) extendsDataBaseUtilDataBaseUtil(this class contain all methods and information for connect to the database)
and I crate the database object with DataBase db = new DataBase();
And I want something like:
DataBase(this class have all the methods for the databases) extendsDataBaseUtilDataBaseUtil(this class contain all methods and information for connect to the database)
and classes for example:
DogSQL(all the methods for the table dog on the database)CatSQL(all the methods for the table cat on the database)
and I create the database object with DataBase db = new DataBase(); and call methods like db.methodFromDogSQL();
I don't understand how do this. I don't understand if a need use abstract, interface, inheritance for this or which is the best implementation for this. I'm starting and my knowledge in java is a bit basic, so I want learn how do this type of stuff.
dogdb.someMethod(); catdb.otherMethod();instead of onedbobject for both? Also, are you sure all your SQL operations will affect only one table at a time? (most properly-normalized databases require join queries to do anything interesting)