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

  • SEARCH
  • Home
  • 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 7707291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:19:21+00:00 2026-06-01T00:19:21+00:00

In our system we have an entity Product , which might have various custom

  • 0

In our system we have an entity Product, which might have various custom properties. Set of properties might differ from product to product, and is stored in a field of type List<Property>. Properties are of different types (strings, ints, double) and might have some special characteristics, e.g. they might be multivalued, might be a value of s specific range, a value from the given list etc. Value of the property is always contained in the string field Value.

Now my current problem is to implement validation of these properties and I am kind of stuck on what approach to take in part of erpresentation of the validation results. Requirements that I have to satisfy:
– Results of the validation will be used by other application layers, so the resulting API should be clear and easy to use
– Each error should have a distinct representation
– Users of the API should have enough information to understand error specifics (for example for range errors they should be provided with minimal possible value, maximal possible value and actual value)

Here are the approaches I have considered so far:

  1. Classes hierarchy. There is one base abstract class ValidationError, and each specific error will be reflected in a inherited class. If error has any specifics, corresponding class will have necessary fields to store all the information. Example:

    public abstract class ValidationError
    {
        // common fields and methods, if any
    }
    
    public class IncorrectFormatValidationError : ValidationError
    {
        // just empty class, nothing to add here
    }
    
    public class RangeValidationError : ValidationError
    {
        public object MinValue { get; set; }
    
        public object MaxValue { get; set; }
    }
    

    This approach seems to be rather redundant to me because of variety of actually empty classes. Furthermore usage of such a API does not seem to be right (if (typeof(error) == typeof(RangeValidationError)) – nonsense!). However this is the first thing that came to my mind.

  2. Errors enumeration and, where necessary, classes hierarchy. All errors are represented with enumeration. There is one class ValidationError that is used in most cases, and when additional info is necessary for specific error, the inheritor is created, basically the same way as in the first approach. Example:

    public enum ValidationErrors
    {
        IncorrectFormat,
        ValueNotWithinRange,
        ...
    }
    
    public class ValidationError
    {
        public ValidationErrors ErrorType { get; set; } 
    
        public ValidationError(ValidationErrors type)
        {
            this.ErrorType = type;
            ...
        }
    
        // common fields and methods, if any
    }
    
    public class RangeValidationError : ValidationError
    {
        public object MinValue { get; set; }
    
        public object MaxValue { get; set; }
    
        public RangeValidationError(object minValue, object maxValue) :
            base(ValidationErrors.ValueNotWithinRange)
        {
            ...
        }
    }
    

    This approach looks much better, however there are drawbacks as well. The biggest one is that we as a API users cannot be guaranteed that when we have the error of type say ValueNotWithinRange, we are dealing with class of type RangeValidationError, and if we are not – how do we handle it? Idially I would like to have some design-level feature that would prevent even existing of such situations, since I am not the onyl one who develops the API. Another issue with this approach is that if most errors will in the end require some additional info, we’ll eventually end up with the same aprroach number 1.

Anyone has any thoughts to share on these two approaches or suggest a better one? I will highly appreciate any response. Thanks in advance.

  • 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-06-01T00:19:22+00:00Added an answer on June 1, 2026 at 12:19 am

    It might be a good idea to take a step back and rethink the whole “multiple classes representing validation errors” approach, because it’s almost guaranteed that you already have a hierarchy of validators.

    Any validation error could be perfectly specified given:

    1. The validator that failed to accept the value of a property
    2. The name of the property
    3. The value that failed to validate

    Any further information (e.g. limits of a range, a regular expression that did not match) is already present on the the validator instance and can be accessed through that.

    So what about having just one validation error class that looks like this:

    public sealed class ValidationError
    {
        public Validator Validator { get; set; }
        public string PropertyName { get; set; }
        public object AttemptedValue { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our current system we have a custom formula builder system which is using
We have two tasks (T1 and T2) in our vxWorks embedded system that have
I have a process where an incoming user request to our system is being
While debugging an issue with our system, I have discovered a thread contention that
I have a problem with a client, who cannot log in to our system.
We have a system where our front end is either a Rich Client application
I have a library that interacts with our phone system, ie, Hey phone, call
We have a query that is taking around 5 sec on our production system,
I have a C# app that subscribes to a topic on our messaging system
We have a Data Access service in our SOA WCF system. This service is

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.