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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:29:29+00:00 2026-05-13T05:29:29+00:00

Over a few years, I have have written a few validation classes and have

  • 0

Over a few years, I have have written a few validation classes and have always wonder what people thinks is the best way of handling them.

I’ve seen and done each of the following and am curious to your know opinions and why.

Scenario 1, Message Counting

class ValidationClass1
{
    public List<string> ValidationMessage { get; set; }

    public void Validate(x)
    {
        // pseudo-code
        if (!rule_logic1)
        {
            ValidationMessage.Add("Error in logic 1");
        }
        if (!rule_logic2)
        {
            ValidationMessage.Add("Error in logic 2");
        }
    }
}

Scenario 2, Returning an Object or Tuple

class ValidationClass
{

    public Tuple<bool, List<string>> Validate(x)
    {
        List<string> ValidationMessage = new List<string>();
        bool passed = true;

        // pseudo-code
        if (!rule_logic1)
        {
            ValidationMessage.Add("Error in logic 1");
            passed = false;
        }
        if (!rule_logic2)
        {
            ValidationMessage.Add("Error in logic 2");
            passed = false;
        }

        return new Tuple<bool, List<string>>(passed, ValidationMessage);
    }

}

In Scenario 1, the ValidationMessage list could be the return type as well. Regardless, calling code would have to check the count property of the list to see if the data passed or not. If it was only a singular rule, the returning string length would need to be checked via string.IsNullOrEmpty(x).

In Scenario 2, a custom object or tuple would be the return type so that the calling code would have to have knowledge of the returning code and evaluate a boolean property to see if it passed and then the validation messages.

So, in your opinion, which way do you prefer or if you have a different preference, I’d be curious to hear that as well.

Thanks

  • 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-13T05:29:29+00:00Added an answer on May 13, 2026 at 5:29 am

    I’ve used a variant of Martin Fowler’s Notification Pattern to handle validation and associated validation error messages.

    Here is the specific class that might address your “Boolean or Count” question:

    class Notification...
        private IList _errors = new ArrayList();
    
        public IList Errors {
          get { return _errors; }
          set { _errors = value; }
        }
        public bool HasErrors {
          get {return 0 != Errors.Count;}       
        }
    

    His pattern uses more granular members to indicate whether general validation failure has occurred (‘HasErrors’ which returns a boolean based on ‘Errors’ collection count) and what specifically has failed (‘Errors’ collection from which you can derive a count) The actual ‘Validate’ code that runs the validation is a separate method altogether (found on the business/domain object that requires validation).

    The pattern might be a bit out to date (including my own previous implementation) but it does expose you to some alternatives and can give you some ideas to build on.

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

Sidebar

Ask A Question

Stats

  • Questions 283k
  • Answers 283k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think your malloc is wrong. It should be board_type… May 13, 2026 at 4:12 pm
  • Editorial Team
    Editorial Team added an answer You need to create a forked process using fork, like… May 13, 2026 at 4:12 pm
  • Editorial Team
    Editorial Team added an answer I found out that the segfault occured when trying to… May 13, 2026 at 4:12 pm

Related Questions

Some of the queries I have written inside MS-Access are getting deleted automatically. And
My company is looking at using SQL Server Compact Edition 3.5 as a datastore
Our win32 applications (written in C++) have been around for over 10 years, and
I have a database where most tables have a delete flag for the tables.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.