At my job, I need to format payments file to be able to communicate with banks. The problem is that all bank ask for a different format. Right now, we use the Template Method pattern [GOF] in a attempt to do this as generics as possible but in result of the same 3 classes repeat for every format.
a class inherit from asbtract absPaymentFile (with Inversion of Control) a class inherit from Payment (contain info about the payment sometime have 1 or 2 attribute different of the others payments classes) a class inherit from absMerchant (contain info about the merchant and some method to implement)
Is there a way to format a file, with "almost" the same information, in several ways better than what we do now ?
this link should provide you a good base line of what i need to do : https://www.vancity.com/lang/fr/SharedContent/documents/CPA_Std005_Specs.doc
It's a .doc !
Thanks !
Having gone down the path of trying to make something which would only need minor tweaks to support multiple formats, I'd say don't. DRY principles don't really apply here because each new format is really and truly independent of the others and may change.
Yes, it might mean copy/pasting fair amounts of code but honestly once one format is done then you don't have to worry about it until the receiving software updates their spec. Also, if that format changes you usually don't want any of those changes to impact your other output code.
In short, this is one of those areas that should only be encapsulated to the point of having some type of plugin architecture. Meaning, all of the classes should implement a basic interface that simply defines how your main app is going to transfer data to it. After that the classes should be able to diverge significantly from each other AND updates in one should have no impact in others.