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

      CodeSOD: A Unique Way to Primary Key

      July 22, 2025

      BrowserStack launches Figma plugin for detecting accessibility issues in design phase

      July 22, 2025

      Parasoft brings agentic AI to service virtualization in latest release

      July 22, 2025

      Node.js vs. Python for Backend: 7 Reasons C-Level Leaders Choose Node.js Talent

      July 21, 2025

      The best CRM software with email marketing in 2025: Expert tested and reviewed

      July 22, 2025

      This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

      July 22, 2025

      I’m a wearables editor and here are the 7 Pixel Watch 4 rumors I’m most curious about

      July 22, 2025

      8 ways I quickly leveled up my Linux skills – and you can too

      July 22, 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

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025
      Recent

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025

      Zero Trust & Cybersecurity Mesh: Your Org’s Survival Guide

      July 22, 2025

      Execute Ping Commands and Get Back Structured Data in PHP

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

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025
      Recent

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025

      “I don’t think I changed his mind” — NVIDIA CEO comments on H20 AI GPU sales resuming in China following a meeting with President Trump

      July 22, 2025

      Galaxy Z Fold 7 review: Six years later — Samsung finally cracks the foldable code

      July 22, 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.

    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 best CRM software with email marketing in 2025: Expert tested and reviewed

    July 22, 2025
    News & Updates

    This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

    July 22, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Rilasciata Linux Kamarada 15.6: Una Distribuzione GNU/Linux Basata su openSUSE

    Linux

    Rancher Releases Patch for CVE-2024-22031 Privilege Escalation Vulnerability

    Security

    CVE-2025-5324 – TechPowerUp GPU-Z IOCTL Handler Memory Leak Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-33043 – APTIOV BIOS Improper Input Validation Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    EchoLeak Zero-Click AI Attack in Microsoft Copilot Exposes Company Data

    June 12, 2025

    EchoLeak Zero-Click AI Attack in Microsoft Copilot Exposes Company Data

    Cybersecurity firm Aim Labs has uncovered a serious new security problem, named EchoLeak, affecting Microsoft 365 (M365) Copilot, a popular AI assistant. This flaw is a zero-click vulnerability, meani …
    Read more

    Published Date:
    Jun 12, 2025 (5 hours, 14 minutes ago)

    Vulnerabilities has been mentioned in this article.

    CVE-2023-24955

    Microsoft Defender Spoofing Vulnerability Allows Privilege Escalation and AD Access

    June 13, 2025

    Microsoft Edge 135 breaks with ERR_INVALID_URL on First-Run Experience on Windows

    April 10, 2025

    Heard about the 16 billion passwords leak? Here are the facts and how to protect yourself

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

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