<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Tushar Koshti</title>
    <description>The latest articles on Forem by Tushar Koshti (@07101994).</description>
    <link>https://forem.com/07101994</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F241067%2F08bd7f69-5fc1-4e7e-b366-181f69cada65.jpeg</url>
      <title>Forem: Tushar Koshti</title>
      <link>https://forem.com/07101994</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/07101994"/>
    <language>en</language>
    <item>
      <title>Factory Design Pattern - Javascript</title>
      <dc:creator>Tushar Koshti</dc:creator>
      <pubDate>Tue, 25 Aug 2020 18:18:49 +0000</pubDate>
      <link>https://forem.com/07101994/factory-design-pattern-javascript-2dib</link>
      <guid>https://forem.com/07101994/factory-design-pattern-javascript-2dib</guid>
      <description>&lt;h2&gt;
  
  
  Factory Design Pattern
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Factory design pattern is one of the creational design patterns.&lt;/li&gt;
&lt;li&gt;Factory design pattern describes how the object should be created.&lt;/li&gt;
&lt;li&gt;It is used to separate the object creation logic from the rest of our code.&lt;/li&gt;
&lt;li&gt;It has only one responsibility. i.e. to create objects only based on the provided inputs.&lt;/li&gt;
&lt;li&gt;It simplifies the object creation logic by having the object creation logic at one place.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to use Factory Design Pattern
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;When we need to keep the object creation logic in one place.&lt;/li&gt;
&lt;li&gt;To separate out the responsibility of object creation from the code which uses these objects.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Code example
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The shape is one of the examples which we can use in our code example.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;shapeFactory&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;createShape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shapeType&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;shapeType&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;square&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Square shape&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rectangle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rectangle shape&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;circle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Shape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Circle shape&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;factory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;shapeFactory&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;circle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;factory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createShape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;circle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;square&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;factory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createShape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;square&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rectangle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;factory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createShape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rectangle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;circle&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Shape {description: 'Circle shape'}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;square&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Shape {description: 'Square shape'}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Shape {description: 'Rectangle shape'}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In this example, you can see that the &lt;code&gt;shapeFactory&lt;/code&gt; is a factory class that creates shape objects based on the &lt;code&gt;shapeType&lt;/code&gt; provided.&lt;/li&gt;
&lt;li&gt;You can find the code in the  &lt;a href="https://github.com/07101994/design-patterns/blob/master/factory.js"&gt;GitHub repository&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  One Last Thing...
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If you'd like to stay in the loop of Software Development then please subscribe to my newsletter. I will try my best to keep you informed about the latest trends and best practices for Software Development.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Please like and follow the blog post. Connect with me on  &lt;a href="https://twitter.com/tushar_koshti"&gt;Twitter&lt;/a&gt;  and  &lt;a href="https://www.linkedin.com/in/tushar-koshti-683b1bb0/"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Let me know in the comments what you will like to learn next... Thanks for visiting the blog...
&lt;/h4&gt;

</description>
      <category>designpatterns</category>
      <category>creationaldesignpattern</category>
      <category>javascript</category>
      <category>factorydesignpattern</category>
    </item>
    <item>
      <title>Singleton Design Pattern - Javascript</title>
      <dc:creator>Tushar Koshti</dc:creator>
      <pubDate>Tue, 25 Aug 2020 09:59:00 +0000</pubDate>
      <link>https://forem.com/07101994/singleton-design-pattern-javascript-2hee</link>
      <guid>https://forem.com/07101994/singleton-design-pattern-javascript-2hee</guid>
      <description>&lt;h2&gt;
  
  
  Singleton Design Pattern
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Singleton design pattern is one of the creational design patterns.&lt;/li&gt;
&lt;li&gt;Singleton design pattern describes how the object should be created.&lt;/li&gt;
&lt;li&gt;It ensures that the class has only one instance and provides a global access point to that instance.&lt;/li&gt;
&lt;li&gt;Singleton design pattern is discovered because of bugs due to multiple instances where only one instance should be present.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  When to use Singleton Design Pattern
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;We need to ensure only one instance of the class is present.&lt;/li&gt;
&lt;li&gt;We need to provide a global access point to a class instance.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Code example
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A logger is one of the real-world use cases in which we want to have a single instance globally.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Logger&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;logger_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;logger_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logger_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Logger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Logger1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;logger_2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Logger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Logger2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;logger_1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Logger {name: 'Logger1'}&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;logger_2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Logger {name: 'Logger1'}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In this example, you can see that even if we try to create 2 different instances of the Logger class there will be only one instance of the Logger class.&lt;/li&gt;
&lt;li&gt;You can find the code in the  &lt;a href="https://github.com/07101994/design-patterns/blob/master/singleton.js"&gt;GitHub repository&lt;/a&gt; .&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  One Last Thing...
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If you'd like to stay in the loop of Software Development then please subscribe to my newsletter. I will try my best to keep you informed about the latest trends and best practices for Software Development.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Please like and follow the blog post. Connect with me on  &lt;a href="https://twitter.com/tushar_koshti"&gt;Twitter&lt;/a&gt;  and  &lt;a href="https://www.linkedin.com/in/tushar-koshti-683b1bb0/"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Let me know in the comments what you will like to learn next... Thanks for visiting the blog...
&lt;/h4&gt;

</description>
      <category>designpatterns</category>
      <category>javascript</category>
      <category>singletondesignpattern</category>
      <category>creationaldesignpattern</category>
    </item>
    <item>
      <title>Get started with VS Code for Node.js development</title>
      <dc:creator>Tushar Koshti</dc:creator>
      <pubDate>Tue, 25 Aug 2020 09:53:09 +0000</pubDate>
      <link>https://forem.com/07101994/get-started-with-vs-code-for-node-js-development-476f</link>
      <guid>https://forem.com/07101994/get-started-with-vs-code-for-node-js-development-476f</guid>
      <description>&lt;h2&gt;
  
  
  &lt;a href="https://code.visualstudio.com"&gt;Code editor&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;As developers, there's one tool we all use much that is a code editor. So we always want a smart code editor that can help and make our work as a developer as easy as possible.&lt;/p&gt;

&lt;p&gt;I personally use the VS Code for Node.js development purposes. I will share some tools and thoughts which I use to make Node.js development easier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Node.js Extensions for VS Code
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint"&gt;ESLint&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;ESLint is a popular extension for VS Code.&lt;/li&gt;
&lt;li&gt;It's a pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript.&lt;/li&gt;
&lt;li&gt;It will detect problems in real-time like unused variables and incorrect variable names like errors easily.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome"&gt;Debugger for Chrome&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Debugger for Chrome allows developers to debug javascript code with developer tools available in Chrome.&lt;/li&gt;
&lt;li&gt;Features are breakpoints, variables values, etc can be used with this extension.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode"&gt;Prettier - Code Formatter&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Prettier code formatter helps us to auto-format the Javascript code when we save the javascript files or using a shortcut(Ctrl + K, F - Windows, Cmd + K, F - Mac).&lt;/li&gt;
&lt;li&gt;Prettier is a configurable code formatter. Helps us to make the code formatting consistent all over the project.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.vscodeintellicode"&gt;Visual Studio IntelliCode&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Visual Studio IntellliCode provides AI-assisted code completion features for Javascript/Typescript, Python and other languages.&lt;/li&gt;
&lt;li&gt;This tool also improves the productivity of the developer as it provides great code completion assistance to developers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker"&gt;Code Spell Checker&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Code Spell Checker is also a great tool that prevents silly mistakes like spelling mistakes and helps the developers to use proper names across your project.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  One Last Thing...
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;If you'd like to stay in the loop of Software Development then please subscribe to my newsletter. I will try my best to keep you informed about the latest trends and best practices for Software Development.&lt;/li&gt;
&lt;li&gt;Please like and follow the blog post. Connect with me on  &lt;a href="https://twitter.com/tushar_koshti"&gt;Twitter&lt;/a&gt;  and  &lt;a href="https://www.linkedin.com/in/tushar-koshti-683b1bb0/"&gt;LinkedIn&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Let me know in the comments what you will like to learn next... Thanks for visiting the blog...
&lt;/h4&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>vscode</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Singleton Design Pattern</title>
      <dc:creator>Tushar Koshti</dc:creator>
      <pubDate>Wed, 30 Oct 2019 04:42:44 +0000</pubDate>
      <link>https://forem.com/07101994/singleton-design-pattern-3h2d</link>
      <guid>https://forem.com/07101994/singleton-design-pattern-3h2d</guid>
      <description>&lt;p&gt;Singleton design pattern makes sure that there should be only one instance of the specific class at a given time. Please refer to the example code for C# implementation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Singleton class Customer&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Customer&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;Lazy&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Customer&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_lazy&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Lazy&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Customer&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Customer&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nf"&gt;Customer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;Customer&lt;/span&gt; &lt;span class="n"&gt;Instance&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;get&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;_lazy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>designpatterns</category>
      <category>csharp</category>
      <category>singleton</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
