<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kajanthuka Ulaganathan on Medium]]></title>
        <description><![CDATA[Stories by Kajanthuka Ulaganathan on Medium]]></description>
        <link>https://medium.com/@kajanthuka?source=rss-6c71048fed37------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*uwlDvPzK6zcTogNMWAFXcw.jpeg</url>
            <title>Stories by Kajanthuka Ulaganathan on Medium</title>
            <link>https://medium.com/@kajanthuka?source=rss-6c71048fed37------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 03:26:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kajanthuka/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[K-Nearest-Neighbor Algorithm]]></title>
            <link>https://medium.com/@kajanthuka/k-nearest-neighbor-algorithm-2717a881a0ba?source=rss-6c71048fed37------2</link>
            <guid isPermaLink="false">https://medium.com/p/2717a881a0ba</guid>
            <dc:creator><![CDATA[Kajanthuka Ulaganathan]]></dc:creator>
            <pubDate>Mon, 26 Feb 2024 00:45:58 GMT</pubDate>
            <atom:updated>2024-02-26T00:45:58.875Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jJCnuQKNbHqV3lPZ2h43qw.jpeg" /><figcaption><a href="https://images.app.goo.gl/K1tx2G953KApHpoGA">https://images.app.goo.gl/K1tx2G953KApHpoGA</a></figcaption></figure><p>The K-Nearest Neighbor algorithm is a non-parametric supervised learning classifier that is used to make classifications or predictions about the grouping of an individual data point.</p><blockquote><strong>Classification problem</strong></blockquote><p>The prediction task is a <strong><em>classification</em></strong> when the target variable is discrete.</p><p>The class of K nearest- neighbors to a new point and assign it the class to which is the majority of K-Neighbors belongs too. It basically creates an imaginary boundary to classify the data. It relies on the idea that similar data points tend to have similar labels or values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xrtrZ-UFednnyh7xw-1W7Q.png" /><figcaption>Photo by Sarang Anil Gotke on <a href="https://www.kdnuggets.com/2020/11/most-popular-distance-metrics-knn.html">Kdnuggets</a></figcaption></figure><p>To determine the closest groups or nearest points for a query point, you need some metrics. It’s used for distance metrics for finding K-nearest neighbors and <strong>“Euclidean distance.”</strong></p><h3><strong>Euclidean Distance</strong></h3><p>Cartesian distance between two points. It is visualized as the length of the straight line that joins the two points that are under consideration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*VCH5ssw5GyNidZYpoGMJ6Q.png" /></figure><p>Calculate the net displacement between the two states of an object</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*D_lo5fDRo4wD_rcjVvWmBQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*UGtEy1Bjm3oIZ7EDdEjdbw.png" /></figure><p>d : dimensional feature vector</p><p>X: Given new data point</p><p>xi, yi: corresponding labels or values of each data point in x.</p><p><strong>Select the K Value for KNN algorithm</strong></p><p>Based on the input data, a cross-validation method is used to select the k value.</p><p>Cross Validation</p><p>Cross-validation is a technique used in machine learning to evaluate the performance of a model on unseen data by dividing the available data into multiple folds or subsets, using one of these folds as a validation set, and training the data.</p><p><strong>Why KNN is useful</strong></p><ol><li>Simplicity and ease of implementation</li><li>It handle numerical and categorical data</li><li>Making it a flexible choice for various types of datasets in classification and regression tasks.</li></ol><p>It is widely disposable in real-life scenarios since it is non-parameteric.</p><p>“Non-parameteric: It does not make any underlying assumptions about the distribution of the data.”</p><h4><strong><em>Machine learning KNN is performed using these steps:</em></strong></h4><ol><li>The K-Nearest Neighbor algorithm is imported from the scikit-learn package</li><li>Load data sets</li><li>Create feature and target variables</li><li>Split data into training and test data</li><li>Generate a K_NN model using neighbors value</li><li>Train or fit the data into the model.</li><li>Predict the future.</li></ol><p>Model algorithm of K-NN</p><pre> # Import necessary modules <br>from sklearn.neighbors import KNeighborsClassifier <br>from sklearn.model_selection import train_test_split <br>from sklearn.datasets import load_iris<br><br># Loading data <br>irisData = load_iris() <br>  <br># Create feature and target arrays <br>X = irisData.data <br>y = irisData.target <br>  <br># Split into training and test sets <br>X_train, X_test, y_train, y_test = train_test_split( <br>             X, y, test_size = 0.2, random_state=42) <br>  <br>knn = KNeighborsClassifier(n_neighbors=7) <br>  <br>knn.fit(X_train, y_train) <br>  <br># Predict on dataset which model has not seen before <br>print(knn.predict(X_test)) </pre><p><strong>Advantages of KNN</strong></p><ol><li>Easy to implement</li><li>Adapts easily</li><li>Few Hyperparameters</li></ol><p><strong>Disadvantages</strong> <strong>of KNN</strong></p><ol><li>Do not scale</li><li>Curse of Dimensionality</li><li>Prone to overfitting</li></ol><p><strong>Applications for KNN</strong></p><ol><li>Data preprocessing</li><li>Pattern Recognition</li><li>Reccomendation Engine.</li></ol><p><strong>References</strong></p><ul><li><a href="https://www.ibm.com/topics/knn">What is the k-nearest neighbors algorithm? | IBM</a></li><li><a href="https://www.analyticsvidhya.com/blog/2018/03/introduction-k-neighbours-algorithm-clustering/#:~:text=The%20K%2DNearest%20Neighbors%20(KNN)%20algorithm%20is%20a%20popular,training%20dataset%20as%20a%20reference.">A Complete Guide to K-Nearest Neighbors (Updated 2024)</a></li><li><a href="https://www.w3schools.com/python/python_ml_knn.asp">Machine Learning - K-nearest neighbors (KNN)</a></li><li><a href="https://www.geeksforgeeks.org/k-nearest-neighbor-algorithm-in-python/">k-nearest neighbor algorithm in Python - GeeksforGeeks</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2717a881a0ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OSI-MODEL OVERVIEW]]></title>
            <link>https://medium.com/@kajanthuka/osi-model-overview-d8190623762d?source=rss-6c71048fed37------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8190623762d</guid>
            <dc:creator><![CDATA[Kajanthuka Ulaganathan]]></dc:creator>
            <pubDate>Thu, 30 Dec 2021 09:53:04 GMT</pubDate>
            <atom:updated>2021-12-30T09:53:04.162Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VCSIxh1TOxt6Zbra" /><figcaption>Photo by <a href="https://unsplash.com/@ptrikutam?utm_source=medium&amp;utm_medium=referral">Pavan Trikutam</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article I&#39;m going to discuss about OSI model. Let’s begin with a straight forward , It’s a deal with systems that open for communication</p><p>“Conceptual framework for describes the functions of a networking system”</p><p><strong>What is exactly OSI ?</strong></p><p>OSI stands for <strong>Open System Interconnection</strong></p><blockquote><em>Layered model that describes how information moves from an application program running on one networked computer to an application program running on another networked computer</em>.</blockquote><p>Developed by the <strong>International Organization for Standardization</strong> (ISO) in 1984.Now considered as an architectural model for the inter-computer communications. The full acronym of the OSI is <strong>ISO OSI.</strong></p><p><strong>Why do we need OSI Model?</strong></p><p>Guide technology vendors and developers so the digital communications products and software products and software programs they create can interoperate and to promote a clear framework that describes the functions of a networking or telecommunications that’s in use.</p><h3><strong>How data t</strong>ransfer <strong>across the OSI model</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CKdGmycT-hIKW6Nu" /><figcaption>Photo by <a href="https://unsplash.com/@martenbjork?utm_source=medium&amp;utm_medium=referral">Marten Bjork</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Data travels from the sending computer down through all the layers to the physical layer where the data is put onto the network cabling, and then sent to the physical layer of the receiving computer where the process reserves and the data travels up through the layers to the application layer of the receiving computer.</p><p><strong>Advantages of OSI</strong></p><ol><li>Standardize the router, switch, motherboard, and other hardware.</li><li>Reduce complexity and standardizes interfaces.</li><li>Facilitates modular engineering.</li><li>Ensure interoperable technology</li><li>Accelerate the evolution</li><li>Protocols can be replaced by new protocols when technology changes</li><li>Provide support for connection-oriented services as well as connectionless service</li><li>Standard model in computer networking</li><li>Supports connectionless and connection-oriented services</li><li>Offers flexibility to adapt to various types of protocols.</li></ol><h3><strong>Structure of the OSI model</strong></h3><blockquote>It’s a seven layer architecture with each layer having specific functionality to perform. All these seven layers work collaboratively to transmit the data from one person to another across the globe.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*q1gcNkxSTiMn8RfXDRbGoA.gif" /><figcaption>Layer specification</figcaption></figure><p><strong><em>How to remember order</em></strong></p><p><strong>”Please Do Not Throw Salami Pizza Away”- </strong>for bottom-to-top.</p><p><strong>“All People Seem To Need Data Processing”- </strong>a top-to-bottom reminder.</p><p>Let’s discuss one by one..</p><blockquote><strong>The Upper Layers</strong></blockquote><p>It deals with application issues and mostly implemented only in software. The highest is closest to the end system user. In this layer, communication from one end-user to another begins by using the interaction between the application layer. It will process all the way to end-user.</p><blockquote><strong>The Lower Layers</strong></blockquote><p>These layers handle activities related to data transport. The physical layer and datalink layers also implemented in software and hardware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AOEC3REaHhP7S6lWQOI3Gg.png" /><figcaption>OSI model</figcaption></figure><blockquote><strong>7. Application layer</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KqCVvr5L-Naa6bUWLuvBbQ.png" /></figure><p>Application layer, both the end user and the application layer interact directly with the software application. This layer sees network services provided to end-user applications such as a web browser or Office 365. The application layer identifies communication partners, resource availability, and synchronizes communication.</p><blockquote><strong>6.Presentation Layer</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*fXWH3zG-MrDiwYrZBBr7EQ.png" /></figure><p>Presentation layer allows you to define the form in which the data is to exchange between the two communicating entities. It also helps you to handles data compression and data encryption. This layer transforms data into the form which is accepted by the application. It also formats and encrypts data which should be sent across all the networks. This layer is also known as a <strong>syntax layer</strong>.</p><blockquote><strong>5.Session Layer</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*f0PTUtr31IUZNE4vwlodVA.png" /></figure><p>This is the layer responsible for opening and closing communication between the two devices. The time between when the communication is opened and closed is known as the session. The session layer ensures that the session stays open long enough to transfer all the data being exchanged, and then promptly closes the session in order to avoid wasting resources. The session layer also synchronizes data transfer with checkpoints.</p><blockquote><strong>4.Transport Layer</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*835zh1gAWXf8TUxFUtZgcg.png" /></figure><p>The transport layer is responsible for transferring data across a network and provides error-checking mechanisms and data flow controls. It determines how much data to send, where it gets sent and at what rate. TCP within the TCP/IP suite is the best-known example of the transport layer. This is where the communications select TCP port numbers to categorize and organize data transmissions across a network. Transport layer helps you to control the reliability of a link through flow control, error control, and segmentation or DE segmentation.</p><p><strong>(i) TCP(Transmission Control Protocol)</strong></p><p>The TCP/IP relationship is similar to sending someone a message written on a puzzle through the mail. The message is written down and the puzzle is broken into pieces. Each piece then can travel through a different postal route, some of which take longer than others. When the puzzle pieces arrive after traversing their different paths, the pieces may be out of order. The Internet Protocol makes sure the pieces arrive at their destination address. The TCP protocol can be thought of as the puzzle assembler on the other side who puts the pieces together in the right order, asks for missing pieces to be resent, and lets the sender know the puzzle has been received. TCP maintains the connection with the sender from before the first puzzle piece is sent to after the final piece is sent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*rETKifm3yCfoW2bBjzhaXg.png" /></figure><p>When an email is sent over TCP, a connection is established and a 3-way handshake is made. First, the source send an SYN “initial request” packet to the target server in order to start the dialogue. Then the target server then sends a SYN-ACK packet to agree to the process. Lastly, the source sends an ACK packet to the target to confirm the process, after which the message contents can be sent. The email message is ultimately broken down into packets before each packet is sent out into the Internet, where it traverses a series of gateways before arriving at the target device where the group of packets are reassembled by TCP into the original contents of the email.</p><p><strong>(ii) UDP(User Datagram Protocol)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*mNi8qeE8lFzRi0EaTq-UXg.png" /></figure><p>On the other hand, is a connectionless internet protocol that allows communication between the server and the client. <strong>User datagram protocol</strong> (UDP) operates on top of the Internet Protocol (IP) to transmit datagrams over a network. UDP does not require the source and destination to establish a three-way handshake before transmission takes place. Additionally, there is no need for an end-to-end connection.</p><blockquote><strong>3.Network Layer</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oGuFZiS_fkCUeVLVaPGUAg.png" /></figure><p>The network layer works for the transmission of data from one host to the other located in different networks. It also takes care of packet routing i.e. selection of the shortest path to transmit the packet, from the number of routes available. The sender &amp; receiver’s IP addresses are placed in the header by the network layer.</p><blockquote><strong>2.Data Link Layer</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dQmQak6Fi-nVpqkrePv6NA.png" /></figure><p>The data-link , or protocol layer, in a program handles moving data into and out of a physical link in a network. This layer handles problems that occur as a result of bit transmission errors. It ensures that the pace of the data flow doesn’t overwhelm the sending and receiving devices. This layer also permits the transmission of data to Layer 3, the network layer, where it’s addressed and routed.</p><p>Data Link Layer is divided into two sublayers:</p><ol><li>Logical Link Control (LLC)</li><li>Media Access Control (MAC)</li></ol><blockquote><strong>1.Physical Layer</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*z84KvTzlZMyhnMxYD_zxog.png" /></figure><p>The lowest layer of the OSI Model is concerned with electrically or optically transmitting raw unstructured data bits across the network from the physical layer of the sending device to the physical layer of the receiving device. It can include specifications such as voltages, pin layout, cabling, and radio frequencies. At the physical layer, one might find “physical” resources such as network hubs, cabling, repeaters, network adapters or modems.</p><p>I hope you will get an idea about OSI model and how it works apparently.</p><p>I will see you in next article.</p><p><strong>References</strong></p><ul><li><a href="https://www.guru99.com/layers-of-osi-model.html">OSI Model Layers and Protocols in Computer Network</a></li><li><a href="https://www.dummies.com/article/technology/programming-web-design/cisco-programming/getting-to-know-the-osi-model-for-the-ccna-exam-200003">dummies - Learning Made Easy</a></li><li><a href="https://www.forcepoint.com/cyber-edu/osi-model">What is the OSI Model?</a></li><li><a href="https://www.techtarget.com/searchnetworking/definition/OSI">What is the OSI model? The 7 layers of OSI explained | Definition from TechTarget</a></li><li><a href="https://www.geeksforgeeks.org/layers-of-osi-model/">Layers of OSI Model - GeeksforGeeks</a></li><li><a href="https://www.javatpoint.com/osi-model">OSI Model: 7 Layers Explained in Computer Network - javatpoint</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8190623762d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SINGLETON DESIGN PATTERN]]></title>
            <link>https://medium.com/@kajanthuka/singleton-design-pattern-5c207722331?source=rss-6c71048fed37------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c207722331</guid>
            <dc:creator><![CDATA[Kajanthuka Ulaganathan]]></dc:creator>
            <pubDate>Thu, 30 Dec 2021 08:50:05 GMT</pubDate>
            <atom:updated>2021-12-30T08:55:52.819Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QhEiwZuBDZZg09DX" /><figcaption>Photo by <a href="https://unsplash.com/@jeremybezanger?utm_source=medium&amp;utm_medium=referral">Jeremy Bezanger</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>“Define a class that has only one instance and provides a global point of access to it ”.</p><blockquote><strong>What is Singleton Design Pattern?</strong></blockquote><p>The Singleton design pattern is software design pattern that restricts the instantiation of a class to one “single” instance , it’s come from under creational design patterns. One Instance per container.</p><blockquote><strong>Why we need Singleton Design Pattern?</strong></blockquote><p>The purpose of the singleton class is...</p><ol><li>Control Object Creation</li><li>Limiting the number of objects only one.</li></ol><blockquote><strong>Usage of Singleton Design Patterns</strong></blockquote><ol><li>Logging</li><li>Caching</li><li>Thread pools</li><li>Configuration settings</li><li>Driver objects</li><li>Database Connections</li><li>Multi Threading</li></ol><blockquote><strong>How does approach to implement a Singleton Design Pattern ?</strong></blockquote><ol><li>Static Member : same class that is the only instance of the class</li><li>Private constructor : restrict instantiation of the class from other classes</li><li>Static method : returns the instance of the class, this is the global access point for outer world to get the instance of the singleton class</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*G9nBNv181W6a_gm-xHL1-A.jpeg" /><figcaption>Class diagram of Singleton Design Pattern</figcaption></figure><blockquote><strong>Singleton design patterns forms in two ways.</strong></blockquote><ol><li>Eager (Early) Initialization</li><li>Lazy Initialization</li></ol><p>Let’s look one by one briefly….</p><ol><li><strong>Eager(Early) Initialization</strong></li></ol><blockquote>“<strong>The instance of Singleton Class is created at the time of class loading</strong>”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OBF5wvhspThQ-gjf" /><figcaption>Photo by <a href="https://unsplash.com/@jeremybezanger?utm_source=medium&amp;utm_medium=referral">Jeremy Bezanger</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If your application always creates and uses an instance of the Singleton or the overhead of creation and runtime aspects of the Singleton are not onerous, you may want to create your Singleton eagerly, like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cNRzeXmEBchW3LerJo1j2Q.png" /><figcaption>Singleton Eager Initialization</figcaption></figure><p><strong>Uses of Early Initialization.</strong></p><ol><li>File System</li><li>Database Connections.</li></ol><p><strong>2.Lazy Initialization</strong></p><blockquote>“<strong>The instance of Singleton Class is created of instance when required.</strong>”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ijv3fianw59FzRhd" /><figcaption>Photo by <a href="https://unsplash.com/@nicolasdc20?utm_source=medium&amp;utm_medium=referral">Nicolas DC</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a> panda</figcaption></figure><p>We’re taking a class and letting it manage a single instance of itself. We’re also preventing any other class from creating a new instance on its own. To get an instance, you’ve got to go through the class itself. We’re also providing a global access point to the instance:</p><p>whenever you need an instance, just query the class and it will hand you back the single instance. As you’ve seen, we can implement this so that the Singleton is created in a lazy manner, which is especially important for resource intensive objects.</p><ol><li><strong>Classic Singleton Pattern Implementation.(Lazy)</strong></li></ol><p>Here we have declared getInstance() static so that we can call it without instantiating the class. The first time getInstance() is called it creates a new singleton object and after that it just returns the same object. Note that Singleton object is not created until we need it and call getInstance() method. This is called lazy instantiation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*GACeegLk6H8lD59rIXyeTA.png" /><figcaption>Singleton Lazy Initialization</figcaption></figure><blockquote><strong>Disadvantage</strong></blockquote><p>No Thread Safe here.</p><p><strong>2.Thread Safe Implementation.</strong></p><p>By adding Synchronized keyword to getInstance() we force every thread to wait its turn before it can enter the method. That is no two threads may enter the method at the same time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U0jNSQzkwqRV2M3xSNQq7A.png" /><figcaption>Singleton Lazy Thread-safe Initialization</figcaption></figure><p>Here using synchronized makes sure that only one thread at a time can execute get Instance().</p><p><strong>Disadvantage</strong></p><p>Every time while creating the singleton object is expensive and may decrease the performance of your program.</p><h3><strong><em>“Best Practice of Singleton Design Pattern is here…..”</em></strong></h3><blockquote><strong><em>Double Check-Locking</em></strong></blockquote><p>If you notice carefully once an object is created synchronization is no longer useful because now object will not be null and any sequence of operations will lead to consistent results.</p><p>So we will only acquire lock on the getInstance() once, when the object is null. This way we only synchronize the first way through, just what we want. With double-checked locking, we first check to see if an instance is created, and if not, then we synchronize.</p><p>The synchronized block is used inside the if condition with an additional check to ensure that only one instance of a singleton class is created.</p><p><strong>“we should consider all applications multithreaded!”</strong></p><p>that time if there multiple threads coming concurrently, each threads coming after the first one have to wait more time to access the method. So it is always best to put the synchronized block wherever its needed.</p><p><strong>Advantage of Double Check-Locking.</strong></p><ol><li>To avoid this extra overhead every time.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yn9M_ub0NGZ2itwyIdnQOw.png" /><figcaption>Double Check-locking</figcaption></figure><p><strong>Volatile</strong></p><p>this keyword ensures that multiple threads handle the unique instance variable correctly when it is being initialized to the Singleton instance.</p><p>Voila! Now I hope everyone get clear idea about this elegant design pattern.</p><p>I will be discussing the different topic in the next article.</p><p><strong>References</strong></p><p>I have referred to the following YouTube video to write this article, which was made by <a href="https://medium.com/u/26403c4bd160?source=user_profile---------1-------------------------------">Krishantha Dinesh</a> , and thanks my dear colleagues .</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fg7RfBhO-rhU%3Fstart%3D105%26feature%3Doembed%26start%3D105&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dg7RfBhO-rhU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fg7RfBhO-rhU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/435a168577d6b78b479e2d902cb2a56d/href">https://medium.com/media/435a168577d6b78b479e2d902cb2a56d/href</a></iframe><ul><li><a href="https://www.journaldev.com/1377/java-singleton-design-pattern-best-practices-examples">Java Singleton Design Pattern Example Best Practices - JournalDev</a></li><li><a href="https://www.geeksforgeeks.org/singleton-design-pattern/">Singleton Method Design Pattern - GeeksforGeeks</a></li><li><a href="https://books.google.lk/books/about/Head_First_Design_Patterns.html?id=GGpXN9SMELMC&amp;printsec=frontcover&amp;source=kp_read_button&amp;hl=en&amp;redir_esc=y">Head First Design Patterns</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c207722331" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DESIGN PATTERNS IN JAVA]]></title>
            <link>https://medium.com/@kajanthuka/design-patterns-in-java-6709b1af6d97?source=rss-6c71048fed37------2</link>
            <guid isPermaLink="false">https://medium.com/p/6709b1af6d97</guid>
            <dc:creator><![CDATA[Kajanthuka Ulaganathan]]></dc:creator>
            <pubDate>Tue, 14 Dec 2021 08:11:55 GMT</pubDate>
            <atom:updated>2021-12-14T10:25:23.760Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qZSVPjurhgr8RZbS" /><figcaption>Photo by <a href="https://unsplash.com/@drastic_graphics?utm_source=medium&amp;utm_medium=referral">Marty O’Neill</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>“ A pattern is a regularity found in the natural world, human-made design, or abstract concepts. As a result, a pattern’s elements repeat in a predictable way.”</p><h3><strong>What are Design Patterns</strong>?</h3><p>In Software engineering a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn’t a finished design that can be transformed directly into code. It is a description or template for a how to solve a problem that can be used in many different situations</p><h3>Intention of Design Patterns</h3><p>A design pattern systematically names, motivates, and explains a general design that address a recurring designing problem in object — oriented systems. It describes the problem the solution, when to apply the solution, and its consequences. It also gives implementation hints and example.</p><h3>Creatures</h3><p>Gang of Four (1994)</p><p>Erich Gamma,</p><p>Richard Helm,</p><p>Ralph Johnson,</p><p>John Vlissides</p><p><a href="https://www.amazon.com/gp/product/0201633612/">Design Patterns: Elements of Reusable Object-Oriented Software</a></p><p>which initiated the concept of Design Pattern in Software development.</p><p>“Various classes and frameworks are provided to enable users to implement these design patterns.”</p><h3>Why do we need design patterns?</h3><p>“Solve common problem”</p><p><strong>Way of solving</strong></p><ol><li>to properly create a class</li><li>to initiate an object</li><li>to interact between objects</li><li>to write loosely coupled code</li><li>to write reusable code</li></ol><h3>Benefits of Design Patterns</h3><ol><li>Robust code</li><li>Code Reusability</li><li>High maintainability</li><li>Reduce total cost of ownership</li><li>Loosely coupled Applications</li><li>provide transparency to the design of an application</li><li>provide clarity to the system architecture and the possibility of building a better system</li></ol><h3>Classification of Design Patterns.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rULadvkT_6DZpO5a" /><figcaption>Photo by <a href="https://unsplash.com/@alicegrace?utm_source=medium&amp;utm_medium=referral">Alice Dietrich</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Design patterns are divided into three categories</strong></p><ol><li>Creational Design Patterns : provide solution to initiate an object in the best possible way for specific situations</li><li>Structural Design Patterns : provide different way to create a class structure</li><li>Behavioral Design Patterns : provide solution for better interaction between objects and how to provide to lose coupling and flexibility to extend easily</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*u3C-5IEYRBCQyge8c_Uf5g.png" /></figure><h3>Best Practices of Design Patterns</h3><ol><li>Keep it simple stupid(KISS)</li><li>Excess of everything is bad</li><li>Focus on loosely coupled code</li><li>Design first, Code later</li></ol><p><strong>References</strong></p><ul><li><a href="https://www.journaldev.com/1827/java-design-patterns-example-tutorial">Java Design Patterns - Example Tutorial - JournalDev</a></li><li><a href="https://www.javatpoint.com/design-patterns-in-java">Design Patterns in Java - Javatpoint</a></li></ul><p>I hope you will understand this. I will be discussing about Singleton pattern in the next article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_J5Kt_MOFXMe53JyOpIQ-w.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6709b1af6d97" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>