25 votes

Swift 1.2 Singleton Implementation

You could simplify the above significantly: ...
20 votes

Singleton Database class

You shouldn't be sharing Connection instances, because ADO is already doing the job for you, it uses object pooling behind the ...
19 votes
Accepted

Singleton Design Pattern implementation in a not traditional way

Your implementation does the trick. For what it's worth, I would consider your implementation the current "traditional way". It is thread-safe. The static constructor is guaranteed to run only once, ...
  • 2,889
18 votes

Swift 1.2 Singleton Implementation

First and foremost, printing text to the console is absolutely pointless for an iOS application. It's okay to do it as an easy way to test whether our code is working as intended, but we don't want ...
  • 25.2k
15 votes
Accepted

Modern C++ Singleton Template

Okay so first of the obligatory Singletons are bad practice so you probably shouldn't make it easy to write bad code. Ignoring the fact that the class probably shouldn't exist at all we can look at ...
  • 16.4k
14 votes

Modern C++ Singleton Template

Singletons make it hard to test your code, and in my job I'd reject this at review for encouraging the development of untestable features. That said, I'll continue reviewing despite that. No need for ...
11 votes

Singleton Database class

Just commenting on ... the comments in the source (sorry): I think they add a lot of noise, and don't provide any improved clarity (in this case). They're mostly restating what the following line of ...
  • 550
9 votes

Singleton Design Pattern implementation in a not traditional way

There's a potential bug with this scenario. According to this Jon Skeet post, if an exception is thrown inside the static constructor, it is never retried. Which ...
  • 12.3k
8 votes
Accepted

Can we now `implement Singleton` using Java 8?

ConcurrentMap As was pointed out in the comments: in the Multiton.get() method: ...
  • 96.9k
7 votes
Accepted

Storing messages for the application's runtime

General Notes I had to look at your code quite hard before I figured out what it does. Despite having variable names and method names that are descriptive, I still found it hard to 'get it'. Comments ...
  • 96.9k
7 votes

Singleton Database class

First, you can use implicit typing when the type is easily determined from the RHS, so: DataTable _resultTable = new DataTable(); becomes: ...
  • 5,167
7 votes

Singleton Database wrapper

Singleton I wouldn't call your Database class a singleton wrapper, as you can have multiple instances of it (not of the ...
  • 25k
7 votes

Generic singleton array with archiving and insertion functions

As my comment explains, there are some things about your code I definitely don't understand. This answer will focus on the parts that I know need to be changed. So, starting from the top... ...
  • 25.2k
6 votes
Accepted

Proper way to wait end of a service and singleton design

Bug? The catch block is a bit suspicious here: ...
  • 110k
6 votes
Accepted

Singleton-ish RMI Server

In this program there is a single remote server which performs miscellaneous work. Because there is only one server, it seems like a singleton pattern could fit well. Let us see the definition ...
  • 50.1k
6 votes

Singleton method for Redis connection in Python

The Singleton pattern is a way to work around the absence of global variables in Java. But Python has global variables, and it's usually possible to write shorter and simpler initialization code if ...
  • 49.3k
6 votes

Thread safe templatized singleton class

Don't use the Singleton pattern But do you think it is really thread safe good singleton? Please excuse my pedantry and let me say that the only good use of the Singleton pattern is to not use it ...
  • 4,240
6 votes
Accepted

Client to connect to server and show a text menu

Regarding static solution, I agree with your teacher. This design makes handling nested menus virtually impossible. Once you consider submenus, it becomes obvious ...
  • 54.4k
6 votes

Two-way data binding

A few notes: This data binding is not two way. If it was two way I should be able to update the either the view or the model and have changes propagate to the other. See this SO post. The code you ...
  • 3,436
6 votes

Singleton class and correct way to access it in C++

Thread safety Accessing the singleton is thread-safe. The change in C++11 has forced compilers to implement the construction of local static variables (like ...
  • 6,428
6 votes
Accepted

Storing singleton instances in a generic utils class

Let me just express the first thing that came to mind when I read this question's title: Not another Singleton question. Let's ignore in the following that Singletons are an anti-pattern in Object-...
  • 25.1k
6 votes
Accepted

ASP.NET Core singleton with a thread-safe property that can be changed

That will lock it down for sure. If you know you will have more reads then writes, which is common, you should look at the ReaderWriterLockSlim class. What you have will only allow one read and one ...
  • 4,178
5 votes
Accepted

Correct usage for singleton and reusability?

Thread Safety There are a number of cases where this code is not thread safe. Thread safety is extremely important if you are going to ensure that your entire application will only every have a ...
5 votes

Manage Sessions within a Singleton

There are several remarks I could tell on your singleton implementation but since there's a far more better expert than me on these things, I'll reference his work. His name is Jon Skeet and he has an ...
  • 5,553
5 votes
Accepted

Singleton base class

This line isn't needed in Python 3: # -*- coding: utf-8 -*- so you should probably just remove it. UTF-8 is assumed. Your docstring is indented - why? It's not ...
  • 9,553
5 votes

Android app with config and customization classes

Public class, private Interface? I'm pretty confused by this setup. The meaning is always trying working towards the most highest object( this case interface) possible. I'm thinking that you created ...
  • 3,862
5 votes
Accepted

ResourceManager class consisting of multiple singletons

The fact that you have "Manager" as part of the name of the class is a code smell. This class violates the Single Responsibility Principle. In particular, ...
5 votes

Client to connect to server and show a text menu

using System That first line of code makes it unnecessary to give the fully qualified class name. However, you always use ...
5 votes
Accepted

Singleton Provider

I hope that code base isn't sprinkled with calls to that SingletonProvider! A "singleton provider", conceptually, makes no sense. This is highlighted by this ...
5 votes
Accepted

Header only c++ singleton pattern implementation

I have a problem with this because template<class Type> struct SingleTon { static std::unique_ptr<Type> instance; This is still a static storage ...
  • 92.3k

Only top scored, non community-wiki answers of a minimum length are eligible