Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6600877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:40:50+00:00 2026-05-25T18:40:50+00:00

I have a data model which contains an array of Product objects. Before reporting

  • 0

I have a data model which contains an array of Product objects. Before reporting from this model I am required to run a set of rules which check the integrity of each Product object in the model. One way I can think of doing this is to have a Rule interface e.g.

public interface CheckRule {
    boolean runRule(Product p);
}

For each rule I can then have a separate Rule class which implements the CheckRule interface. I can then have a double loop to run all the rules e.g.:

for (Product p : Products) {
   for (Rule r : Rules) {
      if (! r.runRule(p) {
              // report on the broken rule
      }
   }
}

If I have hundreds of rules however I end up with hundreds of Rule classes, which seems a messy way to do it. An alternative is to have a single RuleManager class, which has a separate method for each rule e.g.

public class RuleManager {

    boolean runRule1(Product p) { // rule 1 logic}

    boolean runRule2(Product p) { // rule 2 logic}

    boolean runRule3(Product p) { // rule 3 logic}

    etc...
}

This reduces the number of classes, but means that I end up with a single class with hundreds of methods. Both methods feel wrong to me, and I was wondering if there is a Design Pattern which covers this scenario which I could use instead?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:40:51+00:00Added an answer on May 25, 2026 at 6:40 pm

    I think you’ll find that you can often parameterize rules, so that you won’t need anywhere near one class per rule. This is especially true if you’re willing to consider using reflection.

    JSR303, aka Java Validation API, is good for simple field validation, but rapidly runs out of steam when you need to do more complex stuff.

    Drools is not relevant, if I understand the use case – way too heavy.

    Think carefully about how to handle validation errors. You want to be able to report multiple errors – don’t bail out on the first one, your users will hate you. So you probably want to have some kind of error collector object that the validators put the errors in, that is then returned by the validator framework.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model which gets its data from a parser object. I'm thinking
For example I have data model like this Entity: Store Entity: Inventory Entity:Product Attribute:
Hay, I'm using MPTT to create some tree-like data from a model which contains
I have a list of viewmodels which contains vehicle data such as this public
I have a fairly involved managed data model which has a central object with
I have a WCF service which performs CRUD operation on my data model: Add,
I have a NetCDF file, which contains data representing total precipitation across the globe
I have a Model which contains an Address and Person twice, once for the
I have a Core Data model in which a Task entity includes an optional
I have a data model in which I have an Item that can belong

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.