Tag:Hungry man

  • Design mode – 18) singleton mode

    Time:2021-9-6

    class STWindow { static Window win; private STWindow() { } public static Window GetInstance() { if (win == null || !win.IsVisible) { win = new Window(); win.Height = 200; win.Width = 200; } return win; } } class Singleton { static Singleton _singleton; private Singleton() { } public static Singleton GetInstance() { if (_singleton == […]

  • Singleton mode

    Time:2021-8-21

    Singleton mode Singleton pattern is one of the simplest design patterns in Java. This type of design pattern is a creation pattern, which provides the best way to create objects. This pattern involves a single class that is responsible for creating its own objects while ensuring that only a single object is created. This class […]

  • Java singleton mode

    Time:2021-6-28

    Singleton mode The runtime in JDK is a typical hungry Chinese style The source code is as follows: public class Runtime { private static Runtime currentRuntime = new Runtime(); /** * Returns the runtime object associated with the current Java application. * Most of the methods of class <code>Runtime</code> are instance * methods and must […]

  • Singleton in multithreading

    Time:2021-3-12

    Hungry man style class Single { private static final Single s = new Single(); private Single (){} public static Single getInstance() { return s; } } Sluggard style class Single { private static Single s = null; private Single(){} public static Single getInstance() { if(s == null) { synchronized(Single.class) { if(s == null) s = […]

  • Go unlocks the singleton pattern of design pattern

    Time:2020-9-28

    preface Hello, everyone. I’m asong. This is my 16th original article. Thank you for your attention. Today, I’d like to share with you the singleton pattern of design pattern and implement it with go language. The students who are familiar with Java must be familiar with singleton pattern, which is a very common software design […]

  • Java singleton design pattern

    Time:2020-8-17

    Design pattern: the most effective way to solve a certain kind of problem. Singleton design pattern: solve the problem that only one object exists in memory for a class. To ensure that the object is unique: 1. In order to avoid creating such objects too much in other programs, it is forbidden for other programs […]

  • Initial Learning Notes for Design Patterns (Single Case Patterns)

    Time:2019-5-20

    About design patterns, long ago through reading some information on the Internet about the design patterns (recommended big-story design patterns), although it seems to understand, but each time when the need to use the relevant design patterns, always can not remember, mainly for each design pattern use scenario has not been thoroughly studied, has remained […]