Reputation: 135
I am new to the pattern way of coding and would like to start implementing patterns in my code. I have a webservice that has multiple operations and receives different xml inputs for each operation(having its own schema). I would like to implement a pattern to validate the input provided.
My design: Have an interface IValidate implement the interface to EntityAValidate, EntityBValidate etc.., each implemented validate method will check for validity of the xml and also do the individual node validation such as the string cannot have special characters etc..,
My questions : Can we use any other design? please let me know the pattern name How can I reuse some common validations like numeric check, date check across operations How can the selection of corresponding validator be done automatically?
Upvotes: 2
Views: 630
Reputation: 16519
I would recommend you to start reading about DP and then get to know many of them. This way you will just realize when and which one fits or not your needs. Design Patterns are meant to be used when you do have an specific need, its means that "the most you use the better" is a very bad approach. Hope it helps!
Im leaving two recomendations on DP literature; Head First - Design Patterns and Elements of Reusable Object Oriented Software
Upvotes: 0
Reputation: 485
Based on this statement "I have a webservice that has multiple operations and receives different xml inputs for each operation", the Command Pattern would probably be a good fit. It would apply more generally though, it need not be specific to validation.
The Command Pattern encapsulates each operation as an object, each derived from a common base class (call it class Operation) which provides an 'execute' method. From each incoming xml operation, you would instantiate the corresponding Operation sub-class, passing them to some operation processing entity who calls execute.
You could build your validation into this, adding a "validate" method to your Operation base class. The processor could then "validate" each Operation before "execute"ing it.
In general, I agree with the commenters on your post. You should study the design patterns themselves, then they'll jump out at you when your solving problems. Don't pick a pattern and try to cram it into an existing design.
Upvotes: 1