I am currently developing a java application, which will communicate with a SQL server. Therefore I created the class
Database which is responsible for
I want to be able to add data to the database. In this example, the table is called job. Therefore I created a class
Job. Besides these jobs, there will be (many) different things, which will be stored in the database. My question is: Where do I put my method
addJob(Job j)? So far, I can think of three possible solutions:
Add the method
addJob(Job j)to the
Databaseclass which provides abstraction for the rest of the program. The rest of the program does not have to worry how this is implemented. The downside of this is, that the
Databasewill get very large eventually.
Create a seperate class
JobHandlerwith the constructor
public JobHandler(Database d)which accepts a Database. In this
JobHandlerI plan to provide the
addJob(Job j). My problem is here, on which level should I interact with the
Databasesince there are currently no public methods except
close(). Should I create a method which accepts pure sql statements? This does not look very good to me.
Make the class
Databaseabstract and extend it so that I implement the missing methods here. Downside is, that I cannot pass the database around and use the same connection for multiple queries of different kinds.
What would one do to solve this problem? How should I structure my classes that they don't get too large and also not too much of the database class has to be exposed to the classes which implement the methods to deal with the data?
Edit Please note, that job is a random class, which should just serve as an example for the data which is stored in the database.