This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Need a pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need a pattern" Watch "Need a pattern" New topic

Need a pattern

Ashish Malik
Ranch Hand

Joined: Jul 11, 2010
Posts: 50
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

Joined: Mar 22, 2000
Posts: 13037
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.

Ashish Malik
Ranch Hand

Joined: Jul 11, 2010
Posts: 50
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:
I agree. Here's the link:
subject: Need a pattern
It's not a secret anymore!