I've such case. User can export several object types (transaction, invoice, etc) to external accounting system. Export algorithm has steps:
- fetch objects by some filter
- export objects one by one to the accounting system (webservice method per object type)
- register the fact that given document was exported, so it wont be exported again
- prepare summary for user (num of exported documents, error messages etc)
The algorithm is the same for all object types but there are some important differences which must be handled:
- different types
- different target webservice method, different object to DTO mappings
- different filters per object type
I've considered few solutions:
- don't treat the export algorithm as code duplication and implement an algorithm per object type. Export of any data to any external system may be described by such algorithm - does it mean that we should always have one general class to export anything to anywhere?:)
- move the differences to strategies (one strategy interface to create abstraction for all differencies) - I even implemented it.
- use generics - unfortunately i'm coding in PHP and it's not possible
The question:
Is creating a separate export algorithm per object type a code duplication?
Maybe all of them should be treated as seperate UseCases?
If it's a duplication then what techniques to avoid it should I consider?
Aucun commentaire:
Enregistrer un commentaire