I have a complicated validation logic that has to be executed in Java/Linux backend and in C# .NET GUI/Windows application, and I would like to be DRY.
The logic could be accessible to both via webmethod on server part, but the validation has to be executed every time user changes the data, so calling webmethod repeatedly is not good enough. What are the ways to solve this problem and is it even possible?
I'm currently not using any scripting languages and if it's possible, I would like to avoid adding any languages into solution.
Currently, I'm considering following ways to go about:
What I would do: design a
declarative language to describe the constraints to be apply on validation, implement a parser for it and read a description file in a in-memory model, implement a source code generator based in the model.
If you think you can describe those restrictions as JSON-formatted-text, you can:
templatingpackage to generate the language specific source from the in-memory model (again in the Java world, I had good experiences with Apache's Velocity )
But then again, that would be my preference: I did similar things 3-4 times in the recent past, so that I'm feeling at large with the approach (and aware of the drawbacks of 'source code generation' - the major one: whatever custom refinements on the generated code need to be applied, they are in danger of being overwritten at the next generation: better generate the code as classes and derive from them to customize the behaviour).