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 6100523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:23:48+00:00 2026-05-23T13:23:48+00:00

I have a business model with many classes in, some logical entities within this

  • 0

I have a business model with many classes in, some logical entities within this model consist of many different classes (Parent-child-grandchild.) On these various classes I define constraints which are invariant, for example that the root of the composite should have a value for Code.

I currently have each class implement an interface like so…

public interface IValidatable
{
    IEnumerable<ValidationError> GetErrors(string path);
}

The parent would add a validation error if Code is not set, and then execute GetErrors on each child, which in turn would call GetErrors on each grandchild.

Now I need to validate different constraints for different operations, for example

  1. Some constraints should always be checked because they are invariant
  2. Some constraints should be checked when I want to perform operation X on the root.
  3. Some additional constraints might be checked when performing operation Y.

I have considered adding a “Reason” parameter to the GetErrors method but for a reason I can’t quite put my finger on this doesn’t feel right. I have also considered creating a visitor and having a concrete implementation to validate for OperationX and another for OperationY but dislike this because some of the constraint checks would be required for multiple operations but not all of them (e.g. a Date is required for OperationX+OperationY but not OperationZ) and I wouldn’t like to have to duplicate the code which checks.

Any suggestions would be appreciated.

  • 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-23T13:23:48+00:00Added an answer on May 23, 2026 at 1:23 pm

    You have an insulation problem here, as your classes are in charge of doing their own validation, yet the nature of that validation depends on the type of operation you’re doing. This means the classes need to know about the kinds of operations that can be performed on them, which creates a fairly tight coupling between the classes and the operations that use them.

    One possible design is to create a parallel set of classes like this:

    public interface IValidate<T>
    {
        IEnumerable<ValidationError> GetErrors(T instance, string path);
    }
    
    public sealed class InvariantEntityValidator : IValidate<Entity>
    {
        public IEnumerable<ValidationError> GetErrors(Entity entity, string path)
        {
            //Do simple (invariant) validation...
        }
    }
    
    public sealed class ComplexEntityValidator : IValidate<Entity>
    {
        public IEnumerable<ValidationError> GetErrors(Entity entity, string path)
        {
            var validator = new InvariantEntityValidator();
            foreach (var error in validator.GetErrors(entity, path))
                yield return error;
    
            //Do additional validation for this complex case
        }
    }
    

    You’ll still need to resolve how you want to associate the validation classes with the various classes being validated. It sounds like this should occur at the level of the operations somehow, as this is where you know what type of validation needs to occur. It’s difficult to say without a better understanding of your architecture.

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

Sidebar

Related Questions

I have a business model called Customer which has many required properties (via DataAnnotations)
I have a business logic classes that are written in pure C# (without any
I have some business objects which use: Web.Configuration.WebConfigurationManager.AppSettings.Item(SomeSetting) Now that I'm breaking those objects
In my business model I have Entity class (IPoint interface ) that has a
I have an application in CakePHP that lists businesses. I have a business model/controller,
I have a business user who tried his hand at writing his own SQL
I have a business case whereby I need to be able to specify my
If I have a business object with 50 fields, and I need to populate
A lot of the time I will have a Business object that has a
Here's my problem at a high level: We have two business applications. App1 inputs

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.