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.

  1. checks file location csv files
  2. for each csv file finds, load csv file, parse , update customer data updated data

thats it.

however im torn between couple of ways this.

  1. have single updater() class everything.
  2. 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: implements updateinstance. insert request.
  • class deleteinstance: implements updateinstance. delete request.
  • class changeinstance: implements updateinstance. update request.

  • interface updatesetbuilder: produces updateset somewhere.

  • class csvupdatesetbuilder: implements updatesetbuilder reading csv file. singleton object.
  • interface updateparser: takes csv line , produces updateinstance (or refuses it).
  • class insertparser: implements updateparser. singleton object. detects , parses insert request.
  • class deleteparser: implements updateparser. singleton object. detects , parses delete request.
  • class changeparser: implements updateparser. singleton object. detects , parses update request.

the different updateparsers 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 of customerrecords , applies updateset it.
  • interface updatetypedoer: different types of operations, execution point of view.
  • class insertdoer: implements updatetypedoer. detects insertinstance objects , applies them data.
  • class deletedoer: implements updatetypedoer. detects deleteinstance objects , applies delete request data.
  • class changedoer: implements updatetypedoer. detects changeinstance objects , applies update request data.

the different updatetypedoers 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

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -