java - Better way to organize read/write actions in my project -


my code contains following read/write methods write data database

read methods like

  1. public byte[]readfile(arg1)
  2. public byte[] readfile(arg1, arg2)
  3. public inputstream readfile(arg1, arg2)
  4. public mystream readfile(arg1, arg2)
  5. public byte[] readfile(arg1, arg2, arg3)

write methods like

  1. public string[] writefile(arg1)
  2. public string[] writefile(arg1, arg2)
  3. public mystream writefile(arg1, arg2) -> file written outputted stream
  4. public string[] writefile(arg1, arg2, arg3)

various classed access these methods read , write purpose. kindly provide me better way organize in better way.

i have centralized part read/write happen.

someone please me choosing appropriate pattern organize well.

you this:

interface databaseservices {   ... listing methods want "combine"  class  databaseservicesimpl implements databaseservices {   ... implementing methods  enum databaseservicesprovider implements databaseservices {   instance;   private final databaseservices impl = new databaseservicesimpl(...   ... forwarding service calls impl object 

the above has advantage "fully" unit-testable (if create enum , put methods on it; break ability test clients using enum).

from there, go existing source code, , throw away methods access data base; replacing them calls like

databaseservices services = databaseservicesprovider.instance; ... services.whatever() 

where: "enum part" somehow optional. find want such db related services central authority thing (in other words: singleton). , enums provide nice, clean solution "global" aspect. if don't need central instance (which better thing anyway), forget part.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -