Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 2, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 2, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 2, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 2, 2025

      The Alters: Release date, mechanics, and everything else you need to know

      June 2, 2025

      I’ve fallen hard for Starsand Island, a promising anime-style life sim bringing Ghibli vibes to Xbox and PC later this year

      June 2, 2025

      This new official Xbox 4TB storage card costs almost as much as the Xbox SeriesXitself

      June 2, 2025

      I may have found the ultimate monitor for conferencing and productivity, but it has a few weaknesses

      June 2, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      May report 2025

      June 2, 2025
      Recent

      May report 2025

      June 2, 2025

      Write more reliable JavaScript with optional chaining

      June 2, 2025

      Deploying a Scalable Next.js App on Vercel – A Step-by-Step Guide

      June 2, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      The Alters: Release date, mechanics, and everything else you need to know

      June 2, 2025
      Recent

      The Alters: Release date, mechanics, and everything else you need to know

      June 2, 2025

      I’ve fallen hard for Starsand Island, a promising anime-style life sim bringing Ghibli vibes to Xbox and PC later this year

      June 2, 2025

      This new official Xbox 4TB storage card costs almost as much as the Xbox SeriesXitself

      June 2, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Single or Mingle

    CodeSOD: Single or Mingle

    April 9, 2025
    CodeSOD: Single or Mingle

    Singletons is arguably the easiest to understand design pattern, and thus, one of the most frequently implemented design patterns, even- especially– when it isn’t necessary. Its simplicity is its weakness.

    Bartłomiej inherited some code which implemented this pattern many, many times. None of them worked quite correctly, and all of them tried to create a singleton a different way.

    For example, this one:

    public class SystemMemorySettings
    {
        private static SystemMemorySettings _instance;
    
        public SystemMemorySettings()
        {
            if (_instance == null)
            {
                _instance = this;
            }
        }
    
        public static SystemMemorySettings GetInstance()
        {
            return _instance;
        }
    
        public void DoSomething()
        {
        ...
            // (this must only be done for singleton instance - not for working copy)
            if (this != _instance)
            {
                return;
            }
        ...
        }
    }
    

    The only thing they got correct was the static method which returns an instance, but everything else is wrong. They construct the instance in the constructor, meaning this isn’t actually a singleton, since you can construct it multiple times. You just can’t use it.

    Hostinger

    And you can’t use it because of the real “magic” here: DoSomething, which checks if the currently active instance is also the originally constructed instance. If it isn’t, this function just fails silently and does nothing.

    A common critique of singletons is that they’re simply “global variables with extra steps,” but this doesn’t even succeed at that- it’s just a failure, top to bottom.

    [Advertisement]
    Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous Article14 Best Free and Open Source Electronic Design Automation Tools
    Next Article Personalizziamo un po’ GNOME – Versione 2025

    Related Posts

    News & Updates

    The Alters: Release date, mechanics, and everything else you need to know

    June 2, 2025
    News & Updates

    I’ve fallen hard for Starsand Island, a promising anime-style life sim bringing Ghibli vibes to Xbox and PC later this year

    June 2, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    WCAG 3.0’s Proposed Scoring Model: A Shift In Accessibility Evaluation

    Tech & Work

    CVE-2025-4886 – iSourcecode Sales and Inventory System SQL Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-4058 – Projectworlds Online Examination System SQL Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    What is torrenting? BitTorrent, legal issues, how it works, and more

    Development

    Highlights

    News & Updates

    Representative Line: Simplest Implementation

    February 11, 2025

    As the saying goes, there are only two hard problems in computer science: naming things,…

    Lakers Charmander Evolution Shirt

    March 16, 2025

    Appium 1.4.13 How to resolve error: Could not detect Mac OS X Version from sw_vers output: ‘10.12 ‘]?

    July 30, 2024

    Regexes Got Good: The History And Future Of Regular Expressions In JavaScript

    August 20, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.