I have to deal with a system where data is screen scraped then parsed and structured into Classes. I use regular expressions for the parsing to validate the data coming in and the regex groups make it easy to pull out the data. This works well, however, I have an issue where other developers utilizing my libraries sometimes need to extend the functionality to parse new or additional data.
Currently, the way I currently handle being able to extend is through a simple Interface that standardizes methods to pass the data for parsing. I then leave it on the developer to handle the parsing in the implementation. This works OK at the top level, they instantiate the main object and add their implementation to a collection. When parsing, the collection of interfaces is checked for any matches and passes data to their implemention when applicable.
However, I have an issue with finding a good solution for child classes since there's often a collection of data where each object needs to be extended. It's clunky to have to add a new implementation to each instance. I could probably figure out something where the implementation type is added, and then each instance uses reflection to instantiate an implementation. But, this seems really cludgy and overkill.
This is a simple example, but should give you an idea of the structure: Account PaymentCollection Payment
It's possible that a developer will want Payment to do more parsing and have more properties that the class currently provides. It's even possible they want to include a method for a computation. Is there an easy way to do this?
Maybe the solution is the extension methods, and to simply expose a shared property to allow the developers to add more regex patterns. Then the extension methods could expose data with a Function.
If someone has other ideas or a better solution, I'd really appreciate it.
Thanks
Aucun commentaire:
Enregistrer un commentaire