In the PLO is not yet strong, so hence the question. There is a database on MySQl, it has 20 tables. I write application on Java. I create for processing each table, a separate class. The first question is - is it right to do that? And second, do I need an interface here or some class from which everything will then be inherited. The fact is that the fields, of course, are different for all these classes, and the methods are different in general. The methods are all similar, but the implementation is different, this is understandable, either the interface or the parent class is needed here, but basically only 3 methods are similar (selection, deletion, updating), but even in some classes there are several methods for retrieving data from the database . So if you think about it, only 2 methods are similar (deleting and modifying a record). Actually here it enters into a stupor. Is it necessary to make an interface or a parent class due to a couple of methods of the same type, if each class will in any case implement a couple of methods in its own way? If I do something wrong, tell me.

  • If the tables are different, then there is no point in making them all have a common ancestor. - KoVadim
  • @KoVadim tables are all different. Is it right to do this at all? For each table to create a class? Or better? - NoName
  • one
    And who knows what in those tables. Maybe there is a sense of one class for two tables or three classes for one. And maybe java is not needed there. Who knows. - KoVadim
  • The code is not written because "it is right" and "everyone is doing it . " Interfaces and classes should be used in code and perform tasks. Accordingly, they are needed when used and not needed when not used. More precisely for the general case does not answer. - default locale
  • In general, there is nothing wrong with that. You can also see how the DAO pattern and the Repository pattern are implemented to work with the database. - Alex Krass

1 answer 1

Since all the tables are different, judging by the description in the question, there is no point in doing either the ancestor or the interface. For each individual table, you simply create your own class, the so-called entity or bin, which has only fields (corresponding to the fields in the table) and get / set methods for accessing their values. Methods of working with the database is better to put in a separate class, as mentioned @artex_x in his answer.