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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:31:28+00:00 2026-05-11T01:31:28+00:00

Say you have these two methods: Number 1: void AddPerson(Person person) { // Validate

  • 0

Say you have these two methods:

Number 1:

void AddPerson(Person person) {   // Validate person   if(person.Name != null && IsValidDate(person.BirthDate)     DB.AddPersonToDatabase(person); } 

Number 2:

void AddPerson(string name, DateTime birthDate) {   Person p = new Person(name, birthDate);   DB.AddPersonToDatabase(person); } 

Which of the two methods is the best one? I know the first one is more correct OO-wise, but I feel the second is more readable, and you don’t have to make sure the object is valid as the parameters make sure of this. I just don’t like to having to validate the objects anywhere I pass them as parameters. Are there other approaches?

EDIT: Thx for all the answers. To clarify, validating in the constructor and a IsValid method is of course a good approach, but in my code the valid state of the person is often dependant of the context and could vary from method to method. This could of course be a sign of bad design.

The code is just a example to describe the problem.

  • 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. 2026-05-11T01:31:28+00:00Added an answer on May 11, 2026 at 1:31 am

    The first shouldn’t have to validate person.Name and person.BirthDate – they should be validated automatically by the Person constructor. In other words, if you’re passed a Person, you should know that it’s valid.

    On the other hand, you’d have to check that person isn’t a null reference.

    It’s sometimes worth having convenience methods like the second version to avoid having to explicitly call the constructor quite as often though. It should usually just call the Person constructor and then delegate the work to the first form.

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

Sidebar

Related Questions

Let's say I have these two variables $number = 1; $word = one; and
Say I have two tables: create table parent ( number not null, constraint parent_pk
Say I have a database called Poll and have these two table structures. poll
Let's say we have these two classes: public class Base { public static int
Let's say I have these two arrays: string[] arr1 = new string[2]{Hello, Stack} string[]
We have two separate web-apps, say 'retailUI' and 'bulkUI'. These two are basically two
Say I have two classes: Supplier, and Account. These classes are connected via has_one
Say I have two files where there is one number per line File 1
I have two methods (in C#): List<Pizza> CookPizza(List<Order>); List<HappyCustomers> DeliverPizza(List<Pizza>); These operations have no
Say I have two classes class Driver{ //attributes of driver ,ex: driving licence number

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.