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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:22:07+00:00 2026-06-05T04:22:07+00:00

All tutorials I’ve read till now about Singleton pattern were as below : public

  • 0

All tutorials I’ve read till now about Singleton pattern were as below :

 public sealed class Singleton
 {
      private static readonly Singleton instance = new Singleton();

      private Singleton(){}

      public static Singleton Instance
      {
         get 
         {
            return instance; 
         }
      }
 }

but I already have a class in a assembly that I need to just have one instance of it during application lifetime . I don’t know how to use pattern mentioned above .

for example suppose there is a class X in dll named Y . is the code below correct :

 public sealed class Singleton
 {
      private static readonly Y.X instance = new Y.X();

      private Singleton(){}

      public static Y.X Instance
      {
         get 
         {
            return instance; 
         }
      }
 }

is this a true singleton ? if not , what is a correct way to handle this situation ?

  • 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-05T04:22:10+00:00Added an answer on June 5, 2026 at 4:22 am

    No its not the singleton pattern. The fact that you are calling new Y.X() means anyone can call it. This does not specifically disallow new instances of Y.X()

    However the code is okay if you need to make sure that you refer to only one instance of Y.X in your application. Then you can get it by calling Singleton.Instance.

    This is in fact the Factory pattern (A class dedicated to creating objects), and I would suggest you call the class XFactory or something similar, instead of singleton.

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

Sidebar

Related Questions

I'm learning Eclipse PDT for PHP development. In pretty much all tutorials I've read
ok, so I am stuck at the observer pattern here, almost all tutorials I
I've gone through all the tutorials and read through a ton of forum posts,
I see all those tutorials about how one can use Javascript for input validating
Just download the thing today and read all tutorials available on their site with
I did some research about showing the tables from my application database. all tutorials
I'm confused about the differences between the ViewController.xib and MainWindow.xib. All tutorials, and books
all tutorials tell me to do this: startService(new Intent(this, MyService.class)); but there is no
In all tutorials about MVVM, I see code behind file is of no great
All the tutorials and examples I've found of XSLT processing seem to assume your

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.