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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:23:08+00:00 2026-05-11T17:23:08+00:00

So I got into a friendly argument with a co-worker over a piece of

  • 0

So I got into a friendly argument with a co-worker over a piece of code:

public sealed class NewObject
{
    private string _stuff = string.Empty;

    public string Stuff
    {
        get { return GetAllStuff(); }
    }

    private string GetAllStuff()
    {
        //Heavy string manipulation of _stuff
    }

    public NewObject(string stuffToStartWith)
    {
        _stuff = stuffToStartWith;
    }

    public static NewObject operator +(NewObject obj1, NewObject obj2)
    {
        if (obj1 == null)
            throw new ArgumentNullException();

        if (obj2 == null)
            throw new ArgumentNullException();

        NewObject result = new NewObject(string.Empty);
        result._stuff = String.Concat(obj1._stuff, obj2._stuff);

        return result;
    }
}

The argument was over the operator override. My co-worker feels that it’s not best programming practice to set values of private fields anywhere but the constructor. The solution proposed by my co-worker was to refactor the name of the Stuff property to AllStuff and add a property, Stuff, that has a get AND set accessor and use the new Stuff property in the operator override. Making it look like this:

    public static NewObject operator +(NewObject obj1, NewObject obj2)
    {
        if (obj1 == null)
            throw new ArgumentNullException();

        if (obj2 == null)
            throw new ArgumentNullException();

        NewObject result = new NewObject(string.Empty);
        result.Stuff = String.Concat(obj1.Stuff, obj2.Stuff);

        return result;
    }

I disagree. I feel the first way is better since it keeps the property read-only outside the class. My question is, which way is the best practice for object-oriented design?

  • 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-11T17:23:08+00:00Added an answer on May 11, 2026 at 5:23 pm

    You could give yourself a private set on the property (which would retain visibility or lack thereof while allowing you to use property syntax), but that doesn’t really address the point.

    Within the class, I say that variables are fair game. Anywhere outside, including inherited classes, should get and set the property, but within the declaring class I say it’s OK to assign the private member.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Hypothetically, if you were the service developer, you could use… May 12, 2026 at 6:45 am
  • Editorial Team
    Editorial Team added an answer Someone's created an ICEFaces/Seam archetype, it's not available on any… May 12, 2026 at 6:45 am
  • Editorial Team
    Editorial Team added an answer Use Mercurial and TortoiseHg. May 12, 2026 at 6:45 am

Related Questions

I'm looking for a thread pool library in .NET I should able to push
I got into a mini-argument with my boss recently regarding project failure. After three
I've been using MVC frameworks for a short while now and I really like
I'm working with the Windows 7 audio APIs, and I've hit a wall. Basically,

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.