{"id":573,"date":"2021-05-13T22:15:00","date_gmt":"2021-05-13T20:15:00","guid":{"rendered":"https:\/\/wojciechsiwek.pl\/?p=573"},"modified":"2025-02-02T11:13:08","modified_gmt":"2025-02-02T10:13:08","slug":"wzorzec-singleton","status":"publish","type":"post","link":"https:\/\/wojciechsiwek.pl\/en\/wzorzec-singleton\/","title":{"rendered":"Singleton design pattern"},"content":{"rendered":"<p class=\"wp-block-paragraph\">The time has come for the first design pattern I have described, namely Singleton. It is a creative design pattern whose assumptions are very simple. Nevertheless, using this pattern we get a very convenient tool. Why? I encourage you to read the article.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_86 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Spis Tre\u015bci<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a8d12376927b\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a8d12376927b\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/wojciechsiwek.pl\/en\/wzorzec-singleton\/#Zbudujmy_Wzorzec_od_poczatku\" >Let's build a Pattern from scratch<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/wojciechsiwek.pl\/en\/wzorzec-singleton\/#Przyklad_Uzycia\" >Example of use<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/wojciechsiwek.pl\/en\/wzorzec-singleton\/#Podsumowanie\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Zbudujmy_Wzorzec_od_poczatku\"><\/span>Let's build a Pattern from scratch<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let's start by presenting the very idea and the purpose of using this pattern. This pattern is to control that only one object of a given class is created during the operation of the application. The programmer does not have to focus on creating mechanisms referring to the same object by himself, because the class itself makes sure that no more objects are created.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default, when creating an object, we use the constructor of a given class, which, even if we do not create it ourselves, is created by default. Usually, creating an object looks like this (I will describe patterns using Java as an example):<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\" data-line=\"\">MyClass object = new Myclass();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To prevent the creation of many objects, let's start by prohibiting the possibility of creating them at all. How to do it? It is enough that we will not be able to use the constructor, i.e. we will change the access modifier from public to private. Then our MyClass class will look like this:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\" data-line=\"\">public class MyClass {\n    private static MyClass exampleObject;\n    \n    private MyClass() {}\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Okay, but why do I need a class from which you can't create any object at all\u2026. Well, now it's time to implement a very important basic mechanism for creating an object based on a static method in our class.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\" data-line=\"\">public class MyClass {\n    private static MyClass exampleObject;\n    \n    private MyClass() {}\n\n    public static MyClass getExampleObject(){\n         if (exampleObject == null) {\n            exampleObject = new MyClass();\n        }\n        return exampleObject;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The conditional statement tells us that if an object has been created, the method will return a ready, previously created object, and if it has not been created, it will create it. To use a class created in this way, it should be called through a static method as follows:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\" data-line=\"\">MyClass object = Myclass.getExampleObject();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">At this point, it can already be said that the pattern has been implemented. To test it, we will implement additional methods in our class that increment the number, and then we will try to create several objects of our class and call the method of incrementing the number on them. Our class will be as follows:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\" data-line=\"\">public class MyClass {\n    private static MyClass exampleObject;\n    private int number;\n\n    private MyClass() {\n        number = 0;\n    }\n\n    public static MyClass getExampleObject() {\n        if (exampleObject == null) {\n            exampleObject = new MyClass();\n        }\n        return exampleObject;\n    }\n\n    public void incrementNumber() {\n        number++;\n    }\n\n    public int getNumber() {\n        return number;\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"> Now let's use the created class as follows:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\" data-line=\"\">public class Main {\n\n    public static void main(String[] args) {\n\n        MyClass objectOne = MyClass.getExampleObject();\n        System.out.println(&quot;Wartosc z obiektu 1 wynosi &quot; + objectOne.getNumber());\n        objectOne.incrementNumber();\n        System.out.println(&quot;Wartosc z obiektu 1 wynosi &quot; + objectOne.getNumber());\n\n        MyClass objectTwo = MyClass.getExampleObject();\n        System.out.println(&quot;Wartosc z obiektu 2 wynosi &quot; + objectTwo.getNumber());\n        objectTwo.incrementNumber();\n        System.out.println(&quot;Wartosc z obiektu 2 wynosi &quot; + objectTwo.getNumber());\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The program returns the following values:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"\" data-line=\"\">Wartosc z obiektu 1 wynosi 0\nWartosc z obiektu 1 wynosi 1\nWartosc z obiektu 2 wynosi 1\nWartosc z obiektu 2 wynosi 2\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first call to object 1 creates an object for us, and then the incerementNumber () method performs an operation on the number. Trying to create a second object means that we do not get a new object with a zero value, but assign to the objectTwo object in fact the same object as in the case of objectOne. This solution makes it possible to easily use the same object in different places in the application, which significantly facilitates the creation of more flexible software.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Przyklad_Uzycia\"><\/span>Example of use<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As an example, I wrote a simple console game where the application generates a random number from a set range. The user's task is to guess this number and enter it into the terminal. The game continues until the user guesses the drawn number. Then the application displays an appropriate message and indicates how many errors were made before the user correctly guessed the number.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Zgadula class was created first. All application logic is stored in it. The class looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\" data-line=\"\">package com.company;\n\nimport java.util.Random;\n\npublic class Zgadula {\n    private final int randomNumber;\n    private boolean win;\n\n    \/\/podaj minimaln\u0105 i maksymaln\u0105 liczb\u0119 z zakresu z kt\u00f3rego ma by\u0107 wylosowana liczba.\n    public Zgadula(int min, int max) {\n        win = false;\n        Random random = new Random();\n        randomNumber = random.nextInt(max - min + 1) + min;\n    }\n\n    \/\/zwraca wylosowan\u0105 liczb\u0119\n    public int getRandomNumber() {\n        return randomNumber;\n    }\n\n    public boolean isWin() {\n        return win;\n    }\n\n\n    \/\/sprawdza czy podana liczba jest t\u0105 wylosowan\u0105\n    public void checkNumber(int number) {\n        if (this.randomNumber == number) win = true;\n        else {\n            LicznikBledow licznik = LicznikBledow.getLicznik();\n            licznik.addMistake();\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The constructor of this class takes two values: maximum and minimum from the range from which the number is to be drawn, and then assigns these values to the variable randomNumber. Two other methods are helper methods, but let's pay attention to the last method, checkNumber.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This method checks if the number given by the user is the same as the number randomNumber. If the number is correct then the wine flag is set to true. Otherwise, the counter object calls addMistake (). Note how the counter object is declared. Through the static method of the CounterBledow class. Note that the object is created only when the user makes a mistake. Let's move on to this class of the Bledow Counter, and it looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\" data-line=\"\">package com.company;\n\npublic class LicznikBledow {\n    private static LicznikBledow licznik;\n    private int numberOfMistakes;\n\n    \/\/prywatny konstruktor uniemo\u017cliwiaj\u0105cy utworzenie nowego obiektu wprost\n    private LicznikBledow() {\n        numberOfMistakes = 0;\n    }\n\n    \/\/metoda statyczna, kt\u00f3ra tworzy i kontroluje ilo\u015b\u0107 obiekt\u00f3w i ogranicza je do 1\n    public static LicznikBledow getLicznik() {\n        if (licznik == null) {\n            licznik = new LicznikBledow();\n        }\n        return licznik;\n    }\n\n    \/\/inkrementuje ilosc bledow\n    public void addMistake() {\n        numberOfMistakes++;\n    }\n\n    \/\/zwraca ilosc bledow\n    public int getNumberOfMistakes() {\n        return numberOfMistakes;\n    }\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The most important in this class is the constructor, which is private, and the static method getCounter (), which controls the creation and return of the counter object. Right here we have implemented the singleton pattern. It is not possible to create more than one error counter (although that's not entirely true, but more on that later). Okay, but the question may arise why use this design pattern if you could create a regular Bledow Counter class with a public constructor if we only refer to the counter object once in the Guess class and declare it as follows:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\" data-line=\"\">package com.company;\n\npublic class LicznikZwykly {\n    private int numberOfMistakes;\n\n    \/\/klasyczny publiczny konstruktor\n    public LicznikZwykly() {\n        numberOfMistakes = 0;\n    }\n\n    \/\/inkrementuje ilosc bledow\n    public void addMistake() {\n        numberOfMistakes++;\n    }\n\n    \/\/zwraca ilosc bledow\n    public int getNumberOfMistakes() {\n        return numberOfMistakes;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The code is shorter, simpler and seems cleaner. The answer can be seen when we implement our main to create the Zgadula class object. So, let's go:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\" data-line=\"\">package com.company;\n\nimport java.util.Scanner;\n\npublic class Main {\n\n    public static void main(String[] args) {\n        Zgadula zgadula = new Zgadula(2, 6);\n        Scanner scanner = new Scanner(System.in);\n\n        while (!zgadula.isWin()) {\n            System.out.println(&quot;Podaj liczbe: &quot;);\n            zgadula.checkNumber(scanner.nextInt());\n        }\n\n        LicznikBledow licznik = LicznikBledow.getLicznik();\n        System.out.println(&quot;BRAWO! Szukana liczba to &quot; + zgadula.getRandomNumber());\n        System.out.println(&quot;Popelniles &quot; + licznik.getNumberOfMistakes() + &quot; bledow.&quot;);\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After creating the object guessing and scanner for the purposes of reading data to the console, a loop was saved, which is broken only after the correct guessing of the drawn number. And now let's pay attention to the line:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-java\" data-line=\"\">LicznikBledow licznik = LicznikBledow.getLicznik();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It looks like creating a new object based on the CounterBledow class through a static method, but in fact we assign to the value a counter already created in the Guesses class to the object with information about the number of errors made during the game. An example game turn in the console then looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"\" data-line=\"\">Podaj liczbe: \n2\nPodaj liczbe: \n3\nPodaj liczbe: \n4\nPodaj liczbe: \n5\nBRAWO! Szukana liczba to 5\nPopelniles 3 bledow.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notice how easy it is to refer to the previously created object based on the CounterBledow class. In this way, you can implement further classes, such as the menu of this application, where you could display, for example, the number of errors from the previously played round of the game. In the new class, we would create a new object to which we would actually reassign the previously created object via the static method. But it's simple and convenient, isn't it?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Podsumowanie\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The wisely used singleton pattern can significantly make the programmer's work easier and simplify the application code. At one point I mentioned that despite the use of a mechanism that prevents the creation of more objects, this can happen. This can happen if the application is multi-threaded, then there is a risk of creating 2 or more singletons simultaneously. There are ways to prevent this, but it is a topic for a separate article that may be written one day.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I hope that I have introduced as much as possible the ideas of this simple but very useful template and maybe someone will get a revelation and will be convinced of its use in their application.<\/p>","protected":false},"excerpt":{"rendered":"<p>The time has come for the first design pattern I have described, namely Singleton. It is a creative design pattern whose assumptions are very simple. Nevertheless, using this pattern we get a very convenient tool. Why? I encourage you to read the article.<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[26],"tags":[25,23,22],"class_list":["post-573","post","type-post","status-publish","format-standard","hentry","category-programowanie","tag-java","tag-programowanie","tag-wzorce-projektowe"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Wzorzec SingleTon &#8211; Wojciech Siwek<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wojciechsiwek.pl\/en\/wzorzec-singleton\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Wzorzec SingleTon &#8211; Wojciech Siwek\" \/>\n<meta property=\"og:description\" content=\"Przyszed\u0142 czas na pierwszy opisywany przeze mnie wzorzec projektowy, a mianowicie Singleton. Jest to kreacyjny wzorzec projektowy, kt\u00f3rego za\u0142o\u017cenia s\u0105 bardzo proste. Nie mniej jednak u\u017cywaj\u0105c tego wzorca dostajemy bardzo wygodne w u\u017cyciu narz\u0119dzie. Dlaczego? Zach\u0119cam do przeczytania artyku\u0142u.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wojciechsiwek.pl\/en\/wzorzec-singleton\/\" \/>\n<meta property=\"og:site_name\" content=\"Wojciech Siwek\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-13T20:15:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-02T10:13:08+00:00\" \/>\n<meta name=\"author\" content=\"Wojciech Siwek\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Wojciech Siwek\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/wojciechsiwek.pl\\\/wzorzec-singleton\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wojciechsiwek.pl\\\/wzorzec-singleton\\\/\"},\"author\":{\"name\":\"Wojciech Siwek\",\"@id\":\"http:\\\/\\\/wojciechsiwek.pl\\\/#\\\/schema\\\/person\\\/eb4246ee83fb20ed02fc723e28258677\"},\"headline\":\"Wzorzec SingleTon\",\"datePublished\":\"2021-05-13T20:15:00+00:00\",\"dateModified\":\"2025-02-02T10:13:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/wojciechsiwek.pl\\\/wzorzec-singleton\\\/\"},\"wordCount\":1088,\"publisher\":{\"@id\":\"http:\\\/\\\/wojciechsiwek.pl\\\/#\\\/schema\\\/person\\\/eb4246ee83fb20ed02fc723e28258677\"},\"keywords\":[\"java\",\"programowanie\",\"wzorce projektowe\"],\"articleSection\":[\"Programowanie\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wojciechsiwek.pl\\\/wzorzec-singleton\\\/\",\"url\":\"https:\\\/\\\/wojciechsiwek.pl\\\/wzorzec-singleton\\\/\",\"name\":\"Wzorzec SingleTon &#8211; Wojciech Siwek\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/wojciechsiwek.pl\\\/#website\"},\"datePublished\":\"2021-05-13T20:15:00+00:00\",\"dateModified\":\"2025-02-02T10:13:08+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wojciechsiwek.pl\\\/wzorzec-singleton\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wojciechsiwek.pl\\\/wzorzec-singleton\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wojciechsiwek.pl\\\/wzorzec-singleton\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Strona g\u0142\u00f3wna\",\"item\":\"https:\\\/\\\/wojciechsiwek.pl\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Wzorzec SingleTon\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/wojciechsiwek.pl\\\/#website\",\"url\":\"http:\\\/\\\/wojciechsiwek.pl\\\/\",\"name\":\"Wojciech Siwek\",\"description\":\"Programista na pocz\u0105tku swojej \u015bcie\u017cki w IT\",\"publisher\":{\"@id\":\"http:\\\/\\\/wojciechsiwek.pl\\\/#\\\/schema\\\/person\\\/eb4246ee83fb20ed02fc723e28258677\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\\\/\\\/wojciechsiwek.pl\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\\\/\\\/wojciechsiwek.pl\\\/#\\\/schema\\\/person\\\/eb4246ee83fb20ed02fc723e28258677\",\"name\":\"Wojciech Siwek\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/wojciechsiwek.pl\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/cropped-logo.png\",\"url\":\"https:\\\/\\\/wojciechsiwek.pl\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/cropped-logo.png\",\"contentUrl\":\"https:\\\/\\\/wojciechsiwek.pl\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/cropped-logo.png\",\"width\":313,\"height\":306,\"caption\":\"Wojciech Siwek\"},\"logo\":{\"@id\":\"https:\\\/\\\/wojciechsiwek.pl\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/cropped-logo.png\"},\"sameAs\":[\"https:\\\/\\\/wojciechsiwek.pl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Wzorzec SingleTon &#8211; Wojciech Siwek","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wojciechsiwek.pl\/en\/wzorzec-singleton\/","og_locale":"en_GB","og_type":"article","og_title":"Wzorzec SingleTon &#8211; Wojciech Siwek","og_description":"Przyszed\u0142 czas na pierwszy opisywany przeze mnie wzorzec projektowy, a mianowicie Singleton. Jest to kreacyjny wzorzec projektowy, kt\u00f3rego za\u0142o\u017cenia s\u0105 bardzo proste. Nie mniej jednak u\u017cywaj\u0105c tego wzorca dostajemy bardzo wygodne w u\u017cyciu narz\u0119dzie. Dlaczego? Zach\u0119cam do przeczytania artyku\u0142u.","og_url":"https:\/\/wojciechsiwek.pl\/en\/wzorzec-singleton\/","og_site_name":"Wojciech Siwek","article_published_time":"2021-05-13T20:15:00+00:00","article_modified_time":"2025-02-02T10:13:08+00:00","author":"Wojciech Siwek","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Wojciech Siwek","Estimated reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/wojciechsiwek.pl\/wzorzec-singleton\/#article","isPartOf":{"@id":"https:\/\/wojciechsiwek.pl\/wzorzec-singleton\/"},"author":{"name":"Wojciech Siwek","@id":"http:\/\/wojciechsiwek.pl\/#\/schema\/person\/eb4246ee83fb20ed02fc723e28258677"},"headline":"Wzorzec SingleTon","datePublished":"2021-05-13T20:15:00+00:00","dateModified":"2025-02-02T10:13:08+00:00","mainEntityOfPage":{"@id":"https:\/\/wojciechsiwek.pl\/wzorzec-singleton\/"},"wordCount":1088,"publisher":{"@id":"http:\/\/wojciechsiwek.pl\/#\/schema\/person\/eb4246ee83fb20ed02fc723e28258677"},"keywords":["java","programowanie","wzorce projektowe"],"articleSection":["Programowanie"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/wojciechsiwek.pl\/wzorzec-singleton\/","url":"https:\/\/wojciechsiwek.pl\/wzorzec-singleton\/","name":"Wzorzec SingleTon &#8211; Wojciech Siwek","isPartOf":{"@id":"http:\/\/wojciechsiwek.pl\/#website"},"datePublished":"2021-05-13T20:15:00+00:00","dateModified":"2025-02-02T10:13:08+00:00","breadcrumb":{"@id":"https:\/\/wojciechsiwek.pl\/wzorzec-singleton\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wojciechsiwek.pl\/wzorzec-singleton\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/wojciechsiwek.pl\/wzorzec-singleton\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Strona g\u0142\u00f3wna","item":"https:\/\/wojciechsiwek.pl\/"},{"@type":"ListItem","position":2,"name":"Wzorzec SingleTon"}]},{"@type":"WebSite","@id":"http:\/\/wojciechsiwek.pl\/#website","url":"http:\/\/wojciechsiwek.pl\/","name":"Wojciech Siwek","description":"Software developer at the beginning of his career in IT","publisher":{"@id":"http:\/\/wojciechsiwek.pl\/#\/schema\/person\/eb4246ee83fb20ed02fc723e28258677"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/wojciechsiwek.pl\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":["Person","Organization"],"@id":"http:\/\/wojciechsiwek.pl\/#\/schema\/person\/eb4246ee83fb20ed02fc723e28258677","name":"Wojciech Siwek","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/wojciechsiwek.pl\/wp-content\/uploads\/2021\/03\/cropped-logo.png","url":"https:\/\/wojciechsiwek.pl\/wp-content\/uploads\/2021\/03\/cropped-logo.png","contentUrl":"https:\/\/wojciechsiwek.pl\/wp-content\/uploads\/2021\/03\/cropped-logo.png","width":313,"height":306,"caption":"Wojciech Siwek"},"logo":{"@id":"https:\/\/wojciechsiwek.pl\/wp-content\/uploads\/2021\/03\/cropped-logo.png"},"sameAs":["https:\/\/wojciechsiwek.pl"]}]}},"_links":{"self":[{"href":"https:\/\/wojciechsiwek.pl\/en\/wp-json\/wp\/v2\/posts\/573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wojciechsiwek.pl\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wojciechsiwek.pl\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wojciechsiwek.pl\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wojciechsiwek.pl\/en\/wp-json\/wp\/v2\/comments?post=573"}],"version-history":[{"count":33,"href":"https:\/\/wojciechsiwek.pl\/en\/wp-json\/wp\/v2\/posts\/573\/revisions"}],"predecessor-version":[{"id":606,"href":"https:\/\/wojciechsiwek.pl\/en\/wp-json\/wp\/v2\/posts\/573\/revisions\/606"}],"wp:attachment":[{"href":"https:\/\/wojciechsiwek.pl\/en\/wp-json\/wp\/v2\/media?parent=573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wojciechsiwek.pl\/en\/wp-json\/wp\/v2\/categories?post=573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wojciechsiwek.pl\/en\/wp-json\/wp\/v2\/tags?post=573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}