My class derived from SQLiteOpenHelper is getting huge

后端 未结 5 1053
遥遥无期
遥遥无期 2021-02-19 07:55

My class derived from SQLiteOpenHelper is getting bigger and bigger over a time. At the speaking time it is more than 1500 lines of code which is not considered to

5条回答
  •  不思量自难忘°
    2021-02-19 08:25

    You may consider a singleton class to only open and close db connection (or catch, release like a pool) then executing the db operations with command class like in command pattern

    And you can use facade pattern to merge this commands in an execute order for more complex database operations.This will make your code clean and easy to control. like when you change your InsertBookCommand class, all related operations will change behavior due to it.

    To sum up, my solution is:

    Open db connection and pass the db as parameter to commands. then execute the commands.

提交回复
热议问题