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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:36:30+00:00 2026-05-11T22:36:30+00:00

Does this smell? I have a few properties you can only set once. They

  • 0

Does this smell?
I have a few properties you can only set once. They can be set at any time during the objects existence and can not be undone.
I implement then like this.

    private FooThingy _foo;
    public FooThingy Foo
    {
        set { if (null == _foo) _foo = value; }
        get { return _foo; }
    }

But I don’t like it. I feel like I have missed something. Have I?

Edit: Why I don’t have it in the constructor.

I cant go into the details but setting this results in <bad analogy> Melting the wax statue </bad analogy>. And I don’t want my constructor to create already melted objects.

  • 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-11T22:36:31+00:00Added an answer on May 11, 2026 at 10:36 pm

    Set-once-properties violate the principle of least surprise – a caller expects that when a property can be set once, it can be set again. (barring range and compatibility checks, of course – but they are bound to specific values or value combinations).

    Initialize them in the constructor.
    Alternatively, if they are to many / to complex to write all constructors, use a factory/builder class:

    ThingieBuilder tb = new ThingieBuilder();
    tb.FooThingy = 17.23;   // r/w properties
    tb.BarThingy = 42;
    tb.UseExtendedThingamagicAdapter = true;
    Thingie t = tb.Create();
    if (t.Bar==42) // r/o property
      ...
    

    Or, separate the settings in a configuration object, that can be replaced or passed during construction.

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

Sidebar

Related Questions

I have a small app that has a Render thread. All this thread does
I have been writing a small java application (my first!), that does only a
I have some code that roughly does this inside of a GAE worker task:
I have a small widget. I want only a few websites to embed my
I've been fighting with this for a few hours now, and I can't seem
I am working on a Bash shell script that does something like this: #!/bin/bash
Does this below class is immutable? class Immutable { private int x; Immutable(int value)
Does this pattern: setTimeout(function(){ // do stuff }, 0); Actually return control to the
Does this look like it should work? I'm wanting to generate directions from one
Does this code cause a memory leak: int main(){ int * a = new

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.