This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need a pattern

 
Ashish Malik
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am processing an application and it involves validating it. Validation process has many rules to process. Like usual case, application passes through a set of rules and if one rule invalidates it, rest of rules don't execute and application is rejected.
Also rules tend to change for different customers. At one time only one set of customer rules will be active. How should i design my validator class so that it would only suffice to change code for the changed rule and not all rules.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right off hand I would say you need a Validator Interface, with the actual implementing class(es) to be selected by name at runtime from a configuration file.

See the java.lang.Class.forName JavaDocs.

Bill
 
Ashish Malik
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Validator interface is obvious. What i need pattern for are the rules. What i have done for another validator is create classes say: AValidator, BValidator, CValidator. (Rules were divisible into 3 categories)
Each class has set of rules defines in protected methods so that CustomeAValidator could override that method and rest would remain as such.

Each class has following structure:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic