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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:58:53+00:00 2026-06-13T04:58:53+00:00

I have a class: public class Person { public string FirstName { get; private

  • 0

I have a class:

    public class Person
{
    public string FirstName { get; private set; }
    public string LastName { get; private set; }
    public string Email { get; private set; }
    public string Telephone { get; private set; }
    public Address Address { get; private set; }

    public Person(string firstName, string lastName)
    {
        //do null-checks
        FirstName = firstName;
        LastName = lastName;
        Address = new Address();
    }

    public void AddOrChangeEmail(string email)
    {
        //Check if e-mail is a valid e-mail here
        Email = email;
    }

    public void AddOrChangeTelephone(string telephone)
    {
        //Check if thelephone has correct format and valid symbols
        Telephone = telephone;
    }

    public void AddOrChangeAdress(Address address)
    {
        Address = address;
    }

The properties that are not in the constructor are optional, i.e. the person does not need an e-mail, address or telephone. However, I want to give the user of the class an opportunity to create the object without having to first provide the required information and then afterwards have to find out what methods to use to add the information.

Questions:

  1. Is it right to create 3 additional overloads to give them that option?
  2. Should i allow public setters on the optional properties and do the validation there?
  3. If the person marries and changes last name, do I need additional method to change the last name or should I make this setter public too, and just require them in constructor?
  • 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-13T04:58:55+00:00Added an answer on June 13, 2026 at 4:58 am
    1. No.
    2. Yes
    3. Make it public.

    Assuming you are going to have more code in the AddOrChange methods such as formatting logic or validation then I’d do the following. Otherwise, I’d completely get rid of the AddOrChange methods:

    public class Person
    {
        private string _email = string.empty;
        private string _telephone = string.empty;
        private Address _address = new Address();
    
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { 
            get { return _email }
            set { AddOrChangeEmail(value); }
        }
        public string Telephone { 
            get { return _telephone;}
            set { AddOrChangeTelephone(value); }
         }
        public Address Address { 
            get { return _address;  }
            set { AddOrChangeAddress(value); }
        }
    
        public Person(string firstName, string lastName)
        {
            //do null-checks
            FirstName = firstName;
            LastName = lastName;
        }
    
        private void AddOrChangeEmail(string email)
        {
            //Check if e-mail is a valid e-mail here
            _email = email;
        }
    
        private void AddOrChangeTelephone(string telephone)
        {
            //Check if thelephone has correct format and valid symbols
            _telephone = telephone;
        }
    
        private void AddOrChangeAddress(Address address)
        {
            _address = address;
        }
    }
    

    To work with this class you could do any of the following:

    Person p = new Person("Tom", "Jones");
    p.Telephone = "9995551111";
    

    or

    Person p = new Person("Tom", "Jones") { Telephone = "9995551111", Email="spamme@ms.com" }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class public class Person { public string FirstName { get; set;
Assume the following class: class Person { public string FirstName {get;set;} public string LastName
I have following classes public class Person { public string FirstName { get; set;
I have two classes: public class Person { public string FirstName { get {
I've a code below: class Person { public string FirstName { get; set; }
I have the following classes: public class Person { public String FirstName { set;
So I have the following model: public class Person { public String FirstName {
Example-I have a person class Public Class Person Private _fname As String Public Property
I have a class like this, public class person { name Name {set; get;}
I have the following (simplified) classes: public class Person { public string Id {get;

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.