java - Design pattern for import and update actions -
i have small component required application. component loads csv file , updates customer records based on data finds. there single csv file every customer update.
- checks file location csv files
- for each csv file finds, load csv file, parse , update customer data updated data
thats it.
however im torn between couple of ways this.
- have single updater() class everything.
- have update() class representation of loaded csv data, knows how parse csv etc. , have updater() class responsible updating customer records. update() class have updater()
which of these correct solution or there other better solutions this?
if thinking of real general design, consider following:
- class
updateset
: list of updates. csv file if want. - interface
updateinstance
: different types of updates, request point of view. csv line if want. - class
insertinstance
: implementsupdateinstance
. insert request. - class
deleteinstance
: implementsupdateinstance
. delete request. class
changeinstance
: implementsupdateinstance
. update request.interface
updatesetbuilder
: producesupdateset
somewhere.- class
csvupdatesetbuilder
: implementsupdatesetbuilder
reading csv file. singleton object. - interface
updateparser
: takes csv line , producesupdateinstance
(or refuses it). - class
insertparser
: implementsupdateparser
. singleton object. detects , parses insert request. - class
deleteparser
: implementsupdateparser
. singleton object. detects , parses delete request. - class
changeparser
: implementsupdateparser
. singleton object. detects , parses update request.
the different updateparser
s registered csvupdatesetbuilder
, selected through delegation mechanism (i.e. each of them given in turn opportunity of recognizing record, if returns null, next updateparser
given chance).
- class
updater
: takes collection ofcustomerrecords
, appliesupdateset
it. - interface
updatetypedoer
: different types of operations, execution point of view. - class
insertdoer
: implementsupdatetypedoer
. detectsinsertinstance
objects , applies them data. - class
deletedoer
: implementsupdatetypedoer
. detectsdeleteinstance
objects , applies delete request data. - class
changedoer
: implementsupdatetypedoer
. detectschangeinstance
objects , applies update request data.
the different updatetypedoer
s registered updater
, selected through delegation mechanism (i.e. each of them given in turn opportunity of recognizing record, if returns null, next updatetypedoer
given opportunity).
advantages: flexible, , easy evolve , modify (add new data sources, update types, etc). disadvantages: big investment in terms of design , implementation time maybe never pays back. ever going add types of update? different data sources? file formats?
i've thought in design , programming there 2 things can endlessly: abstraction , indirection. knowing how little , how real art.
Comments
Post a Comment