java - Better way to organize read/write actions in my project -
my code contains following read/write methods write data database
read methods like
- public byte[]readfile(arg1)
- public byte[] readfile(arg1, arg2)
- public inputstream readfile(arg1, arg2)
- public mystream readfile(arg1, arg2)
- public byte[] readfile(arg1, arg2, arg3)
write methods like
- public string[] writefile(arg1)
- public string[] writefile(arg1, arg2)
- public mystream writefile(arg1, arg2) -> file written outputted stream
- 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
Post a Comment