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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:03:19+00:00 2026-05-11T19:03:19+00:00

Lets say that one has a class like Person that has associated with it

  • 0

Lets say that one has a class like Person that has associated with it some default settings implemented in a Setting class. Those settings might be things like “Default Title” or “First Name Required”. Correspondingly, other classes like an Address class might also have some default settings. The Setting class persists each setting into a persistent store.

Should one implement a static method in each class like “SetDefaults()” that contains these settings so that an external method can call SetDefaults() on each object type? e.g. Person.SetDefaults() and then Address.SetDefaults()?

Or is there some better object oriented way of doing this?

[Update: this can’t be in the constructor because SetDefaults() should be called from an external class at a particular point in time, rather than each time the object is constructed.]

  • 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-11T19:03:19+00:00Added an answer on May 11, 2026 at 7:03 pm

    I can’t think of many occasions where defaults are truly spanning… given all the different use-cases that an object may go through (not least, things like deserialization – which could end up setting the defaults even though that isn’t what was intended).

    One option here is IoC; IoC containers like StructureMap have the ability to set properties after initialization, and that is then abstracted from the calling code.

    Another option might be some kind of template instance (static), that instances can copy values from. But I think this is risky in a few scenarios. You also get problems if different threads (perhaps requests on a web-server) need different defaults. [ThreadStatic] isn’t a good option (although it is an option).

    Another option (that provides the greatest flexibility) would be to provide a user-settable factory… perhaps via a delegate or event mechanism – but I struggle to see why you might want this scenario. It isn’t one I’ve seen very often…


    re update: if it is only used by the external class; could it perhaps use something like an extension method (rather than the Person class having to know anything about this):

    public static class PersonExt {
        public static void SetDefaults(this Person person) {
           // your code
        }
    }
    

    Since it sounds like the original Person class doesn’t care about SetDefaults, this divorces the logic from Person neatly.

    • 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 one class Foo that has a bunch of logic in
I am reporting on data that lets say has 10 columns. Now some of
I have one field that I need to sum lets say named items However
Let's say you've inherited a C# codebase that uses one class with 200 static
Let's say I am using a framework that has a class called Animal. class
Let's say I have some class X that is going to be injected all
Let's say that you want to create a dead simple BlogEditor and, one of
Lets say that you have websites www.xyz.com and www.abc.com. Lets say that a user
Lets say that I have a header user control in a master page, and
My simplified and contrived example is the following:- Lets say that I want to

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.