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

  • Home
  • SEARCH
  • 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 8338649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:39:33+00:00 2026-06-09T04:39:33+00:00

I am using predefined objects nested inside static class to store objects information at

  • 0

I am using predefined objects nested inside static class to store objects information at single place, and later i used them after some logic to populate normal objects with properties of predefined object.

What will you say that this approach is fine or I can achieve the same by some other efficient and better way?

//Example of storing predefined objects

 public static class RegistrationGift
    {
        public class InvitedRegistrationGift
        {
            public const int Token = 5;
            public const int Dollar = 0;

        }
    }

//how it will be used to populate credit entity (conversion)

Credit credit = new Credit();
credit.Token = RegistrationGift.InvitedRegistrationGift.Token;  

// and so on
  • 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-09T04:39:38+00:00Added an answer on June 9, 2026 at 4:39 am

    Using static classes will not bring major problems, however the singleton pattern may fits better in this case.

    public class RegistrationConfig {
       // private static instance
       private static RegistrationConfig _instance = new RegistrationConfig()
    
       // private constructor prevents the class from being instantiated from outside
       private RegistrationConfig() { }
    
       // instance public accessor
       public static RegistrationConfig Current { get { return _instance; } }
    
       public int InvitationToken { get; set; }
       public int InvitationDollar { get;set; }
    }
    

    Consuming:

    var credit = new Credit();
    credit.Token = RegistrationConfig.Current.InvitationToken;
    

    A variation of this is not to implement the singleton pattern, but keep the .Current accessor and define a public setter, so you can change the active config.

    public class RegistrationConfig {
       // current
       private static RegistrationConfig _current;
    
       // instance public accessor
       public static RegistrationConfig Current { get { return _current; } }
    
       // public setter
       public static void SetCurrent(RegistrationConfig current)
       {
           _current = current;
       }
    
       public int InvitationToken { get; set; }
       public int InvitationDollar { get;set; }
    }
    

    Then, on the app startup you set the config.

    RegistrationConfig.SetCurrent(new RegistrationConfig() { ... });
    

    And consume:

    credit.Token = RegistrationConfig.Current.InvitationToken;
    

    The advantage is that you can create instances with predefined values ​​to use, for example, in unit tests.

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

Sidebar

Related Questions

I want to save some Objects to database with predefined IDs using Hibernate. Is
Is it possible to override system property (timezone etc.) in Java using predefined properties
I have the following assignment: Implement a basic shopping basket without using any predefined
I am using style to define the template of a predefined control. The control
I am using jqGrid v3.8.1 and having trouble passing extra parameters with the predefined
Every new web service you create using visual studio comes with a predefined namespace
Does anyone know any bugs/tricks when using scale_colour_manual to set colors to predefined settings
I am using the Qt QGraphicsScene class, adding pre-defined items such as QGraphicsRectItem ,
Consider an object used to store a collection of items, but that collection may
I'm using mootools 1.4.3 for basic class inheritance. I'm actually converting some code from

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.