<?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 Ritvik Singh Chauhan on Medium]]></title>
        <description><![CDATA[Stories by Ritvik Singh Chauhan on Medium]]></description>
        <link>https://medium.com/@ritvik.singh.chauhan?source=rss-e3cd294ff60a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*E6XldfLA6gle3_O_-4c8JQ.png</url>
            <title>Stories by Ritvik Singh Chauhan on Medium</title>
            <link>https://medium.com/@ritvik.singh.chauhan?source=rss-e3cd294ff60a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 22:51:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ritvik.singh.chauhan/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[JAVA Developer Guide to start with Object Pool Design Pattern]]></title>
            <link>https://medium.com/javarevisited/java-developer-guide-to-start-with-object-pool-design-pattern-3d5fb121b327?source=rss-e3cd294ff60a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d5fb121b327</guid>
            <category><![CDATA[software-design-patterns]]></category>
            <category><![CDATA[email-marketing]]></category>
            <category><![CDATA[creational-patterns]]></category>
            <category><![CDATA[object-pool]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Ritvik Singh Chauhan]]></dc:creator>
            <pubDate>Fri, 03 Mar 2023 02:01:47 GMT</pubDate>
            <atom:updated>2023-03-05T15:28:41.059Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0bPvcBDrcqp6HXwc" /><figcaption>Photo by <a href="https://unsplash.com/@tonicuenca?utm_source=medium&amp;utm_medium=referral">Toni Cuenca</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Imagine a public swimming pool where people come to swim and have fun. This swimming pool has a limited number of swim tubes, which are high in demand.</p><p>To manage the swim tubes effectively, the swimming pool manager has decided to follow the Object Pool design pattern. The manager has created a pool of swim tubes and whenever a swimmer requests for a swim tube, the manager gives them one from the pool. The swimmer uses it for a limited time and returns it back to the pool.</p><p>Now, if there are no swim tubes available in the pool, the swimmer has to wait for one to be returned. The manager makes sure that the returned swim tubes are cleaned and made available for use again. This helps the manager efficiently manage the swim tubes and provide a better experience to the swimmers.</p><p>In this scenario, the swim tubes are the <strong>objects</strong> and the pool of swim tubes is the <strong>object pool</strong>. The swimming pool manager is the <strong>object pool manager</strong> and the swimmers are the <strong>clients</strong>.</p><h3>What is Object Pool Design Pattern?</h3><p>The Object Pool Pattern is one of the creational design patterns from the book “Design Patterns: Elements of Reusable Object-Oriented Software”. The pattern is used in software development to manage the reuse of objects that are expensive to create.</p><p>The pattern is implemented as a container object that holds a pool of objects that are ready to be used. The container object provides an interface for client code to request an object from the pool. When a client requests an object, the container returns an object from the pool if one is available.</p><p>If no objects are available, the container creates a new object, adds it to the pool, and returns it to the client, or it can ask the client to wait until an object is released by another client and available back in the pool.</p><p>The main benefit of the Object Pool design pattern is to improve the performance of an application by reducing the time it takes to create new objects and the memory overhead associated with object creation. The pattern also provides a way to manage the number of objects created, reducing the risk of resource exhaustion and improving the application’s stability.</p><p>This pattern can be useful in a variety of situations, such as database connections, network sockets, and thread pools. By using an object pool, an application can avoid the overhead of creating and destroying objects, making it more efficient and scalable.</p><h3>Object Pool Pattern JAVA Example</h3><p>Let’s say you are building a web application that needs to send email marketing notifications to users. You decide to use a third-party email service provider to handle the sending of emails.</p><p>However, you notice that sending emails can be a slow and resource-intensive process. You don’t want to overload the third-party service with too many requests as you want to use the service within the free tier limit usage (limited connection at a time), but you also don’t want to make users wait too long for their email notifications to be sent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TZHsH5NeeG5zg2oq" /><figcaption>Photo by <a href="https://unsplash.com/ja/@justin_morgan?utm_source=medium&amp;utm_medium=referral">Justin Morgan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>To solve this problem, you decide to use the object pool design pattern to manage a pool of email client objects. Each email client object represents a connection to the third-party email service provider.</p><p>When the application needs to <a href="https://www.java67.com/2018/01/4-examples-to-send-email-with.html">send an email</a>, it retrieves an email client object from the pool. If all email clients are in use, the application waits until one becomes available. Once an email client is available, the application uses it to send the email notification. After the email is sent, the email client is returned to the pool for future use.</p><p>This approach allows the application to send email notifications without overloading the third-party service with too many requests at once. By managing a pool of email clients, the application can reuse existing connections instead of creating new ones for every email, which saves resources and reduces the overall load and usage limit on the third-party service.</p><h4>Object Class Definition</h4><p>In this example, created <strong>EmailClient</strong> class which we will be using in the <strong>pooling manager</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5747d86fa65a01cf1830a8aff928abd9/href">https://medium.com/media/5747d86fa65a01cf1830a8aff928abd9/href</a></iframe><h4>Pool Manager Definition</h4><p>In this example, the <strong>EmailClientPoolManager</strong> class is having fixed pool size and a <strong>Queue</strong> as pool for storing <strong>EmailClient</strong> objects in <strong>FIFO</strong> manner.</p><p>The <strong>borrowClient</strong> method removes an <strong>object</strong> from the <strong>pool</strong> and returns it. If the <strong>pool is empty</strong>, the method <strong>blocks until an object is available</strong>.</p><p>The <strong>returnClient</strong> method accepts an <strong>object</strong> and adds back to the <strong>pool</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04acc675b919f11ea661d1c099bcc133/href">https://medium.com/media/04acc675b919f11ea661d1c099bcc133/href</a></iframe><h4>Client Class Definition</h4><p>Created <strong>EmailSender</strong> class which calls <strong>pool </strong>manager’s <strong>borrowClient</strong> to get one <strong>EmailClient</strong> object, utilize it based on requirements, and finally return back to <strong>pool</strong> manager.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99eb41cbfc337b9803295e033edc0606/href">https://medium.com/media/99eb41cbfc337b9803295e033edc0606/href</a></iframe><h4>Object Pool Pattern in Action</h4><p>Created a <strong>Demo</strong> class that will create multiple <a href="https://www.java67.com/2019/10/how-to-send-email-in-java-using-spring.html"><strong>EmailSender</strong> </a>objects and will wait till execution is over.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/024e8630efc2b1023040e2cf19d12fa9/href">https://medium.com/media/024e8630efc2b1023040e2cf19d12fa9/href</a></iframe><h3>Key Points in the Implementation</h3><ul><li><strong>Object Creation</strong>: If we need the objects on demand then we can choose <strong><em>lazy initialization</em></strong>, or if object creation is expensive and take time then we can go with <strong><em>eager initialization</em></strong> where we create objects at the time of application startup. While implementing a <strong><em>method to create objects</em></strong>, we need to make sure that it is <strong><em>stored in the pool</em></strong> for later use.</li><li><strong>Object Reuse</strong>: To provide a mechanism to reuse objects from the pool instead of creating new ones.</li><li><strong>Object Management</strong>: Need to maintain a pool of objects and keep track of which objects are in use and which are available for reuse. The <strong><em>data structure </em></strong>of the pool varies based on the requirements.</li><li><strong>Pool Size</strong>: Determine the maximum size of the object pool and <strong><em>limit the number of objects</em></strong> that can be created. This helps to<em> </em><strong><em>prevent resource exhaustion and improve performance</em>.</strong></li><li><strong>Object Lifetime</strong>: It’s a good practice to define the <strong><em>lifetime</em></strong> of objects in the pool and <strong><em>remove or replace</em></strong> them as needed.</li><li><strong>Object Validation</strong>: We should implement a mechanism to <strong><em>validate objects</em></strong> in the pool <strong><em>before they are reused</em></strong>. This helps to ensure that the objects are in a <strong><em>suitable state </em></strong>for reuse.</li><li><strong>Synchronization</strong>: Ensure <strong><em>thread safety</em></strong> when <strong><em>multiple threads</em></strong> access the object pool <strong><em>concurrently</em></strong>. This can be achieved through the use of <strong><em>synchronized methods or locks</em></strong>.</li><li><strong>Exception Handling</strong>: Handle exceptions that might occur during the creation, reuse, or validation of objects in the pool.</li><li><strong>Performance Optimization:</strong> Optimize the performance of the object pool by reducing the overhead of object creation and management.</li><li><strong>Object Pool Manager</strong>: Object pool manager should be implemented as a <strong><em>Singleton</em></strong> design pattern to have a<strong><em> single global pool</em></strong> of resources across the application.</li></ul><p><em>What’s your favorite design pattern or if you’d like to understand better any other pattern or topic, feel free to reach out to me on </em><a href="https://www.linkedin.com/in/ritvik92/"><em>LinkedIn</em></a><em> or </em><a href="https://forms.gle/XFsuo1ZbP35gfqAX7"><em>Google Form</em></a><em> and I’ll try to cover it next time!</em></p><p><em>Please share this with all your Medium friends and hit that👏 button below to spread it around even more. Please follow </em><a href="https://medium.com/@ritvik.singh.chauhan"><em>me</em></a><em> for future updates. Thanks for reading.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d5fb121b327" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/java-developer-guide-to-start-with-object-pool-design-pattern-3d5fb121b327">JAVA Developer Guide to start with Object Pool Design Pattern</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JAVA Developer Guide to start with Adapter Design Pattern]]></title>
            <link>https://medium.com/javarevisited/java-developer-guide-to-start-with-adapter-design-pattern-7d1c6c7c891?source=rss-e3cd294ff60a------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d1c6c7c891</guid>
            <category><![CDATA[wrapper-class]]></category>
            <category><![CDATA[software-design-patterns]]></category>
            <category><![CDATA[desing-pattern]]></category>
            <category><![CDATA[converter]]></category>
            <category><![CDATA[adapter-pattern]]></category>
            <dc:creator><![CDATA[Ritvik Singh Chauhan]]></dc:creator>
            <pubDate>Sun, 12 Feb 2023 15:50:43 GMT</pubDate>
            <atom:updated>2023-02-12T15:50:43.331Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W2nKvARiBTywRWau" /><figcaption>Photo by <a href="https://unsplash.com/@photograaapheee?utm_source=medium&amp;utm_medium=referral">Yuvraj Sachdeva</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Imagine you are a chef who only knows how to cook pancakes. One day, a customer walks into your restaurant and orders a waffle. As a chef, you don’t know how to make waffles, but you don’t want to disappoint the customer. This is where the <a href="https://javarevisited.blogspot.com/2016/08/adapter-design-pattern-in-java-example.html">adapter design pattern</a> comes in handy!</p><p>You can use a pancake-to-waffle adapter to solve the problem. The adapter acts as a bridge between the pancake (the existing class) and the waffle (the target class). You can use the pancake batter to make pancakes, but instead of pouring it into a pancake pan, you pour it into the adapter. The adapter will then use its own internal mechanisms to turn the pancake batter into a waffle.</p><p>Now you can serve the customer their desired waffle, even though you only know how to cook pancakes. And the customer will be happy because they got exactly what they wanted.</p><p>So, the <a href="https://javarevisited.blogspot.com/2020/02/23-object-oriented-design-patterns-gof-Java-programmers-developers.html">adapter design pattern</a> helps to make two incompatible classes work together, just like an adapter that converts pancake batter to waffles. Using this example, we can easily understand how the adapter design pattern can be used to adapt existing classes to meet new requirements.</p><h3>What is the Adapter Pattern?</h3><p>The<a href="https://javarevisited.blogspot.com/2011/12/observer-design-pattern-java-example.html"> Adapter Pattern</a> is one of the <strong>structural design patterns </strong>from the book “Design Patterns: Elements of Reusable Object-Oriented Software”. An adapter pattern allows objects with incompatible interfaces to work together. It does so by wrapping the <strong>object</strong> that needs <strong>adaptation</strong> into a class that implements the <strong>desired interface</strong>. This new class is known as the <strong>adapter</strong>, and it acts as a <strong>bridge</strong> between the <strong>client</strong> and the <strong>adaptee</strong> object, converting requests from the original object (<strong>adaptee</strong>) into a format that the <strong>client </strong>can handle.</p><p>The<a href="https://www.java67.com/2012/09/top-10-java-design-pattern-interview-question-answer.html"> Adapter Design Pattern</a> can be used in a variety of contexts, such as when a class needs to be reused that doesn’t have the required interface or when a class needs to be used that has a different interface than what is expected. The pattern provides a flexible and elegant solution for these types of problems and makes it possible for objects to work together that would otherwise be incompatible.</p><h3>Adapter Pattern JAVA Example</h3><p>Let’s consider a scenario where gaming software is being developed and it has to support multiple gaming consoles like Xbox, PlayStation, and Nintendo. The software should be able to receive input from different gaming consoles and display the output on the screen. In this scenario, we can use the adapter design pattern to achieve compatibility between the gaming software and the different gaming consoles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KxP1xKIpsBRvmFU0" /><figcaption>Photo by <a href="https://unsplash.com/es/@glenncarstenspeters?utm_source=medium&amp;utm_medium=referral">Glenn Carstens-Peters</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Target Interface Definition</h4><p>We can define an interface called <strong>GamingConsole</strong> which would have methods for receiving input and displaying output. It will be our <strong>Target</strong> interface for the adapter design pattern example</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1cd768504ad847fe4a4deb60cf1e29f5/href">https://medium.com/media/1cd768504ad847fe4a4deb60cf1e29f5/href</a></iframe><h4>Client Side Definition</h4><p>We can define a class having ‘has-a’ dependency on the <strong>target</strong> interface, along with a required method to play with <strong>GamingConsole </strong>objects.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/930546b9819d478504b605c5301ff809/href">https://medium.com/media/930546b9819d478504b605c5301ff809/href</a></iframe><h4>Adaptee Object Definition</h4><p>Next, we can define <strong>adaptee</strong> concrete classes for each gaming console that we have to use in our gaming software. These classes will contain the specific implementation details for each gaming console. If we observe these <strong>adaptee</strong> classes, these are not implementing the <strong>target</strong> interface <strong>GamingConsole</strong>, hence these can’t be used with the client directly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f6f408246a49de93add8c4038387e39/href">https://medium.com/media/7f6f408246a49de93add8c4038387e39/href</a></iframe><h4>Adapter Classes Definition</h4><p>We can define the <strong>adapter</strong> class for each gaming console that implements the <strong>target</strong> interface <strong>GamingConsole</strong>. This <strong>adapter</strong> class will <strong>adapt </strong>the specific <strong>implementation</strong> of each gaming console <strong>adaptee</strong> while implementing methods from GamingConsole interface.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d434fc6d57d1d4b6965c3b461532b9b6/href">https://medium.com/media/d434fc6d57d1d4b6965c3b461532b9b6/href</a></iframe><h4>Adapter Pattern in Action</h4><p>In the demo code below, created a client, and three adaptee along with respective adapters. The gaming software does not need to be aware of the specific implementation details of each gaming console, as it only interacts with the adapter class which implements the GamingConsole interface. This allows for easy integration of new gaming consoles in the future and makes the software more flexible and maintainable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76b44fefe9c8760007fb5d1b146cccab/href">https://medium.com/media/76b44fefe9c8760007fb5d1b146cccab/href</a></iframe><p>Source Code Available at: <a href="https://github.com/s3c-d43m0n/Desing-Patterns-in-JAVA/tree/main/Structural/Adapter">https://github.com/s3c-d43m0n/Desing-Patterns-in-JAVA/tree/main/Structural/Adapter</a></p><h3>Key Points in the Implementation</h3><ul><li><strong>Identify the Target Interface</strong>: <br>This is the <strong>interface</strong> that the <strong>client</strong> code expects to use. It <strong>defines the methods</strong> that the <strong>client</strong> requires.</li><li><strong>Identify the Adaptee Class</strong>: <br>This is the <strong>class </strong>that needs to be <strong>adapted</strong> to meet the <strong>target </strong>interface requirements.</li><li><strong>Create the Adapter Class</strong>: <br>This is the <strong>class</strong> that <strong>implements</strong> the <strong>target</strong> interface and <strong>delegates</strong> calls to the <strong>adaptee</strong> class. It acts as a <strong>bridge</strong> between the <strong>client</strong> and the <strong>adaptee</strong>.</li><li><strong>Use Composition</strong>: <br>The <strong>adapter</strong> class should use <strong>composition</strong> to hold an instance of the <strong>adaptee</strong> class. This allows the <strong>adapter</strong> to <strong>delegate</strong> calls to the <strong>adaptee</strong>.</li><li><strong>Implement the Target Interface Methods</strong>: <br>The <strong>adapter</strong> class must <strong>implement</strong> all of the <strong>methods defined</strong> in the <strong>target</strong> interface. These methods should <strong>delegate</strong> calls to the <strong>adaptee</strong> class.</li><li><strong>Test the Adapter</strong>: <br>Verify that the <strong>adapter </strong>class works as expected by testing it with <strong>client</strong> code. Ensure that <strong>client</strong> code can use the <strong>adapter</strong> class as if it were the <strong>target</strong> interface, without having to change any of its code.</li><li><strong>Update Client Code If necessary</strong>: <br>The <strong>client</strong> code should be unaware that it is using an <strong>adapter</strong>, and should work seamlessly with the <strong>adapter </strong>class. Usually, we don’t change the <strong>client</strong> code, but if requires then update <strong>client</strong> code to use the <strong>target</strong> interface using <strong>“has a”</strong> relationship.</li></ul><p><em>What’s your favorite design pattern or if you’d like to understand better any other pattern or topic, feel free to reach out to me on </em><a href="https://www.linkedin.com/in/ritvik92/"><em>LinkedIn</em></a><em> or </em><a href="https://forms.gle/XFsuo1ZbP35gfqAX7"><em>Google Form</em></a><em> and I’ll try to cover it next time!</em></p><p><em>Please share this with all your Medium friends and hit that👏 button below to spread it around even more. Please follow </em><a href="https://medium.com/@ritvik.singh.chauhan"><em>me</em></a><em> for future updates. Thanks for reading.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d1c6c7c891" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/java-developer-guide-to-start-with-adapter-design-pattern-7d1c6c7c891">JAVA Developer Guide to start with Adapter Design Pattern</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JAVA Developer Guide to begin with Command Design Pattern]]></title>
            <link>https://medium.com/javarevisited/java-developer-guide-to-begin-with-command-design-pattern-8b0793b1a006?source=rss-e3cd294ff60a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b0793b1a006</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[software-design-patterns]]></category>
            <category><![CDATA[orchestra]]></category>
            <category><![CDATA[observer-design-pattern]]></category>
            <category><![CDATA[command-pattern]]></category>
            <dc:creator><![CDATA[Ritvik Singh Chauhan]]></dc:creator>
            <pubDate>Sat, 08 Oct 2022 14:54:25 GMT</pubDate>
            <atom:updated>2022-10-08T14:54:25.890Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*5OPuY7naV7ObR5HCPZJ9RQ.png" /></figure><p>Have you ever wondered how a music conductor can orchestrate a group of musicians without even knowing how all those musical instruments work? Or how you can drive a car without even knowing the internals working like how the engine works, how it needs fuel to enter the engine, how the valves work, etc.</p><p>Similarly, in most programming scenarios, you want to hide the implementation so that when you look at the topmost problem, it only contains a manageable portion of instructions or code. <a href="https://javarevisited.blogspot.com/2016/05/command-design-pattern-in-java-example-code.html">Command pattern</a> helps in separating the execution of commands from commands themselves, hiding the actual implementation of how the command is executed.</p><h3>What is Command Pattern?</h3><p>The command pattern is one of the behavioral design patterns from well-known <a href="https://en.wikipedia.org/wiki/Design_Patterns">GoF design patterns</a>. In this design pattern, an object (<strong>command</strong>) is used to encapsulate all the information (eg. method name and parameters) requires to trigger an event or perform any action on another object (<strong>receiver</strong>) at a later time and this command object is provided to another object (<strong>invoker</strong>) to perform the action based on <strong>client</strong> requirements.</p><p>It separates the <strong>invoker</strong> object that invokes the operation from the <strong>receiver</strong> object that operates, and thus eliminates hard wiring between them. It makes it easy to add new <strong>commands</strong> because existing classes remain unchanged.</p><p>A particular <strong>method</strong> call can be transformed into a standalone <strong>object</strong> using the <a href="https://javarevisited.blogspot.com/2016/05/command-design-pattern-in-java-example-code.html"><strong>Command</strong> pattern</a>. This adaptation allows us to pass commands as method <strong>arguments</strong>, store them inside other <strong>objects</strong>, exchange linked commands at runtime, and many more intriguing uses.</p><p>A <strong>command</strong> can be <strong>serialized</strong>, which refers to the process of transforming it into the bytes that can be readily written to a file or database, just like any other streamed object.</p><p>These bytes may later be retrieved to serve as the initial <strong>command</strong> object. As a result, you can <strong>schedule</strong> and <strong>postpone</strong> command execution. There’s still more, though! You can queue, log, or send <strong>commands</strong> across the network in the same way.</p><h3>Command Pattern JAVA Example</h3><p>In this example, the <strong>C</strong><a href="https://www.java67.com/2018/05/top-20-system-design-interview-questions-answers-programming.html"><strong>ommand</strong> pattern</a> helps to control the movement of the video game player using a joystick. Based on the inputs being received for joysticks, we can invoke the commands which will move the player.</p><figure><a href="https://javarevisited.blogspot.com/2016/05/command-design-pattern-in-java-example-code.html"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UcFv2y6tBhCr7GyYdNiGSw.png" /></a></figure><h4>Receiver Definition</h4><p>Created an interface for the <strong>Player</strong> to list the instructions available.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a362a8e2b414f86c20b4a206d82b1c74/href">https://medium.com/media/a362a8e2b414f86c20b4a206d82b1c74/href</a></iframe><h4><strong>VideoGamePlayer</strong> class is implementing the <strong>Player</strong> interface and providing <strong>concrete methods</strong> for all movement instructions.</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91913d0e3944c3ee291e4b3e03767ce0/href">https://medium.com/media/91913d0e3944c3ee291e4b3e03767ce0/href</a></iframe><h4>Command Definition</h4><p><strong>Action</strong> interface is having a method <strong>doAction</strong> which is going to be implemented by all concrete commands.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae0d0f09dabb79a120f13f6b82b508a6/href">https://medium.com/media/ae0d0f09dabb79a120f13f6b82b508a6/href</a></iframe><h4>Concrete Command (Implementations)</h4><p>Here in each type of <strong>concrete command</strong>, we are passing <strong>Player</strong> in the <strong>constructor</strong> argument and implementing the <strong>doAction</strong> method to perform a specific action.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e2d8037e7aa3f78d51ef86ffd514b05/href">https://medium.com/media/6e2d8037e7aa3f78d51ef86ffd514b05/href</a></iframe><h4>Invoker Definition</h4><p>Created <a href="https://www.java67.com/2021/10/3-ways-to-send-different-content-types.html"><strong>Controller</strong> </a>interface listing all the <strong>invoker-specific</strong> methods.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61fb685376b57c8c74c0422e84ef16ee/href">https://medium.com/media/61fb685376b57c8c74c0422e84ef16ee/href</a></iframe><h4>Concrete Invoker (Implementation)</h4><p>Provided all the commands to <strong>JoyStickController</strong> class in the <strong>constructor</strong> arguments and implemented all the methods to execute the respective <strong>command</strong>. Here this <strong>concrete invoker</strong> does not need to check the instructions for the <strong>receiver</strong> object thus eliminating all the hard wiring.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/660a17a8554e728e1de6e132213e66ee/href">https://medium.com/media/660a17a8554e728e1de6e132213e66ee/href</a></iframe><h4>Client Implementation in Action</h4><p>In Client class main method, created <strong>Player</strong> object (<strong>receiver</strong>) with <strong>VideoGamePlayer</strong> implementation. Created all the actions (<strong>commands</strong>) required by <strong>JoyStickController</strong> (concrete <strong>invoker</strong>). Based on the input received from the <strong>client</strong> standard input, the <strong>invoker</strong> is indirectly sending instructions to the <strong>receiver</strong> via <strong>commands</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53990bcb58b4b4bc074143a9ab8e02a0/href">https://medium.com/media/53990bcb58b4b4bc074143a9ab8e02a0/href</a></iframe><p>Source Code Available at: <a href="https://github.com/s3c-d43m0n/Desing-Patterns-in-JAVA/tree/main/Behavioral/Command">https://github.com/s3c-d43m0n/Desing-Patterns-in-JAVA/tree/main/Behavioral/Command</a></p><h3>Key Points in the Implementation</h3><ul><li><strong>Clients</strong> need to create all the objects in a specific order: first, create <strong>receivers</strong>, then create <strong>commands</strong>, and last create <strong>invokers</strong>.</li><li>Declare the <strong>command</strong> interface with a single execution <strong>method</strong>.</li><li>Create separate <strong>commands</strong> for each action defined in the <strong>receiver</strong>.</li><li>Provide all the <strong>commands</strong> to the <strong>invoker</strong> object and link with the appropriate action.</li></ul><p><strong>Note: </strong>This pattern is also known as the <strong>Action</strong> or <strong>Transaction </strong>pattern.</p><p><em>What’s your favorite design pattern or if you’d like to understand better any other pattern or topic, feel free to reach out to me on </em><a href="https://www.linkedin.com/in/ritvik92/"><em>LinkedIn</em></a><em> or </em><a href="https://forms.gle/XFsuo1ZbP35gfqAX7"><em>Google Form</em></a><em> and I’ll try to cover it next time!</em></p><p><em>Please share this with all your Medium friends and hit that👏 button below to spread it around even more. Please follow </em><a href="https://medium.com/@ritvik.singh.chauhan"><em>me</em></a><em> for future updates. Thanks for reading.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b0793b1a006" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/java-developer-guide-to-begin-with-command-design-pattern-8b0793b1a006">JAVA Developer Guide to begin with Command Design Pattern</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JAVA Developer Guide to begin with Wire-Tap Enterprise Integration Pattern]]></title>
            <link>https://medium.com/javarevisited/java-developer-guide-to-begin-with-wire-tap-enterprise-integration-pattern-27a385231dd8?source=rss-e3cd294ff60a------2</link>
            <guid isPermaLink="false">https://medium.com/p/27a385231dd8</guid>
            <category><![CDATA[wiretap]]></category>
            <category><![CDATA[software-design-patterns]]></category>
            <category><![CDATA[surveillance]]></category>
            <category><![CDATA[enterprise-integration]]></category>
            <category><![CDATA[eavesdropping]]></category>
            <dc:creator><![CDATA[Ritvik Singh Chauhan]]></dc:creator>
            <pubDate>Sat, 21 May 2022 15:23:23 GMT</pubDate>
            <atom:updated>2022-05-21T15:23:23.984Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cB1oV4soM4IsjhD6SW2Pug.jpeg" /></figure><p>Wire-tapping is the term that is used by surveillance agencies for monitoring phone calls. You are likely aware of this term if you have seen phone-tapping or signal-intercepting activities in most hacking or sci-fi movies/series. A similar concept is also used by Software Enterprises to monitor or intercept data flowing between two services. The Wire-Tap pattern helps in solving the problem of intercepting the data without breaking the flow between services.</p><h3>What is the Wire-Tap Pattern?</h3><p>Wire-Tap is one of the design patterns from the book <a href="https://medium.com/javarevisited/top-5-books-to-learn-spring-boot-and-microservices-for-experienced-java-developers-499a9d921d18">“Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions”</a>, which describes the simple router (also known as Tee) duplicating the message from single input to two output channels.</p><figure><a href="https://www.java67.com/2016/10/top-5-object-oriented-analysis-and-design-patterns-book-java.html"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9ucsKHrrqfjaoAa80DODsw.png" /></a></figure><p>In most cases within software systems, there is a need to monitor or copy the data flowing through. It is usually achieved by intercepting the data and redirecting it to a different location like monitoring dashboards, consoles, filesystems, or the database. Such functionality mustn’t change the original data and interrupt the flow of the services.</p><h3>Wire-Tap Pattern JAVA Example</h3><p>Suppose we are building a Message Eavesdropping System, which intercepts data from Switch. In this example, I am consuming data from a source queue and pushing it to a destination queue using Switch. Added a wiretapping service to intercept the data at the message processor switch.</p><figure><a href="http://www.java67.com/2013/12/strings-in-switch-case-java-7-tutorial.html"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LzoX4QUUIY2eDEIhI2WjdQ.png" /></a></figure><h4>Message Definition:</h4><p>For <strong>Message</strong> model, I have <strong>id</strong>, <strong>text</strong> and <strong>messageDate</strong> fields. Overridden <strong>toString</strong> method to return <a href="https://javarevisited.blogspot.com/2018/02/how-to-parse-json-with-date-field-in-java-jackson-example.html"><strong>JSON</strong> </a>similar string for output.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60e57353ae43f77c9ee6dc48b2f9149a/href">https://medium.com/media/60e57353ae43f77c9ee6dc48b2f9149a/href</a></iframe><h4>Sender Service:</h4><p>In the sender service thread, generating <strong>Message </strong>objects (using <strong>getMessage</strong> method) and pushing those to <a href="https://javarevisited.blogspot.com/2017/03/difference-between-stack-and-queue-data-structure-in-java.html"><strong>queue</strong></a><strong> </strong>in the <strong>run</strong> method. Here <strong>messageId</strong> field is being used to generate a unique key for each generated <strong>Message</strong> object. The <strong>random</strong> field is being used to generate random <strong>text</strong> for the <strong>Message</strong> objects.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/930f73331ba20e4951af6ec4c6c290c3/href">https://medium.com/media/930f73331ba20e4951af6ec4c6c290c3/href</a></iframe><h4>Receiver Service:</h4><p>In receiver service thread, consuming <strong>Message</strong> objects from <strong>queue</strong> in <a href="https://javarevisited.blogspot.com/2012/03/difference-between-start-and-run-method.html"><strong>run </strong>method</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a7a87e94ff5695fd5e569820fe2b59b/href">https://medium.com/media/2a7a87e94ff5695fd5e569820fe2b59b/href</a></iframe><h4>Message Processor Switch:</h4><p>In message processor thread, pulling <strong>Message</strong> objects from <strong>source</strong> queue and pushing those to <strong>destination</strong> queue, but calling <strong>wiretapService </strong>object’s <strong>wiretap</strong> method in between to intercept the message.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5edeace011523381f4e87d2f9ed282b/href">https://medium.com/media/f5edeace011523381f4e87d2f9ed282b/href</a></iframe><h4>Wiretap Service:</h4><p>In the wiretapping service thread, whenever the <strong>wiretap</strong> method is called with the <strong>Message</strong> object, creates a deep-cloned <strong>Message</strong> using the <strong>MessageCloneUtil</strong> utility class and pushes it to its <a href="https://www.java67.com/2022/04/how-to-to-perform-union-of-two-linked.html"><strong>queue</strong> </a>to further processing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78d882d71b2d4d948c2edcf103a26247/href">https://medium.com/media/78d882d71b2d4d948c2edcf103a26247/href</a></iframe><h4>Message Cloning Utility:</h4><p>As we have immutable fields <strong>id</strong> as <strong>long</strong> and <strong>text</strong> as <strong>String</strong> in <strong>Message</strong> objects, so while deep cloning, I am using them as it is. But creating a new <a href="https://www.java67.com/2018/01/how-to-change-date-format-of-string-in-java8.html"><strong>Date</strong> object</a> with the same value as the original <strong>input</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d013afea92965116ff0153fd267a3c81/href">https://medium.com/media/d013afea92965116ff0153fd267a3c81/href</a></iframe><p><strong>Wiretap Pattern in Action:</strong></p><p>In the demo code below, created two queues for creating services. Used both of them to create a <strong>MessageProcessorSwitch</strong> thread, only the <strong>source</strong> queue to create a <strong>SenderService </strong>thread, and only the <strong>destination</strong> queue to create a <strong>ReceiverService</strong> thread. Whenever the <strong>SenderService</strong> thread is pushing a <strong>Message</strong> to the <strong>source</strong> queue, both threads (<strong>ReceiverService</strong> and <strong>WiretapService</strong>) are getting data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1db7895f2b23184b7ec2ab9fe33dbcd8/href">https://medium.com/media/1db7895f2b23184b7ec2ab9fe33dbcd8/href</a></iframe><p>Source Code Available at: <a href="https://github.com/s3c-d43m0n/Desing-Patterns-in-JAVA/tree/main/Integration/Wiretap">https://github.com/s3c-d43m0n/Desing-Patterns-in-JAVA/tree/main/Integration/Wiretap</a></p><h3>Key Points in the Implementation</h3><ul><li><strong>Message </strong>object<strong> </strong>needs to be <strong>deep-cloned</strong> within the <strong>wiretap</strong> method or else if there is a change in the same Message object in downstream systems, then original content might get lost.</li><li>The existing flow between two services must not be interrupted while implementing the pattern. Here <strong>WiretapService</strong> is defined as a <strong>private</strong> field in <strong>MessageProcessorSwitch</strong> class, as we don&#39;t want to expose it to other resources.</li><li>Here I have used <a href="https://javarevisited.blogspot.com/2012/12/blocking-queue-in-java-example-ArrayBlockingQueue-LinkedBlockingQueue.html"><strong>BlockingQueue</strong> </a>objects as <a href="https://www.java67.com/2021/07/how-to-implement-thread-safe-bounded-buffer-in-java.html"><strong>thread-safe</strong> queues </a>as I am having multiple threads pulling/pushing <strong>Message</strong> objects. We can change based on the requirements.</li><li>Here I have used QUEUES for the Consumer/Producer scenario. Most of the <strong>high-end</strong> software systems are using queueing solutions such as <a href="https://javarevisited.blogspot.com/2020/05/top-16-jms-java-messaging-service-interview-questions-answers.html"><strong>JMS</strong> </a>or <a href="https://medium.com/javarevisited/top-10-apache-kafka-online-training-courses-and-certifications-621f3c13b38c"><strong>KAFKA</strong> </a>when dealing specially with <strong>Microservices</strong>.</li></ul><p><em>What’s your favorite design pattern or if you’d like to understand better any other pattern or topic, feel free to reach out to me on </em><a href="https://www.linkedin.com/in/ritvik92/"><em>LinkedIn</em></a><em> or </em><a href="https://forms.gle/XFsuo1ZbP35gfqAX7"><em>Google Form</em></a><em> and I’ll try to cover it next time!</em></p><p><em>Please share this with all your Medium friends and hit that👏 button below to spread it around even more. Please follow </em><a href="https://medium.com/@ritvik.singh.chauhan"><em>me</em></a><em> for future updates. Thanks for reading.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27a385231dd8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/java-developer-guide-to-begin-with-wire-tap-enterprise-integration-pattern-27a385231dd8">JAVA Developer Guide to begin with Wire-Tap Enterprise Integration Pattern</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JAVA Developer Guide to start with Observer Design Pattern]]></title>
            <link>https://medium.com/javarevisited/java-developer-guide-to-start-with-observer-design-pattern-17355b138329?source=rss-e3cd294ff60a------2</link>
            <guid isPermaLink="false">https://medium.com/p/17355b138329</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[observer-design-pattern]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[software-design-patterns]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <dc:creator><![CDATA[Ritvik Singh Chauhan]]></dc:creator>
            <pubDate>Mon, 09 May 2022 12:09:08 GMT</pubDate>
            <atom:updated>2022-10-07T15:47:30.918Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Zt_MjUMW2yrqQZSd" /><figcaption>Photo by <a href="https://unsplash.com/@laughayette?utm_source=medium&amp;utm_medium=referral">Marten Newhall</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>If you have used <a href="https://medium.com/javarevisited/top-10-apache-kafka-online-training-courses-and-certifications-621f3c13b38c">KAFKA</a> or <a href="https://javarevisited.blogspot.com/2020/05/top-16-jms-java-messaging-service-interview-questions-answers.html">JMS</a>, you are likely aware of the publish-subscribe interaction model. In messaging applications, subscriber objects that subscribe to the subject or topic receive a notification when a publisher object generates content on the subject. Subscribers can theoretically be subscribed to more than one publisher. The observer design pattern helps in solving the pub/sub model which allows a number of observer objects to see a subject event.</p><h3>What is the Observer Pattern?</h3><p>The<a href="https://javarevisited.blogspot.com/2011/12/observer-design-pattern-java-example.html"> observer pattern</a> is one of the <strong>behavioral design patterns </strong>from the book “Design Patterns: Elements of Reusable Object-Oriented Software”. An observer pattern is used when there is a one-to-many relationship between objects such as if one object is modified, its dependent objects are to be notified and updated automatically. In this pattern, the object that watches the state of another object is called the <strong>Observer,</strong> and the object that is being watched is called the <strong>Subject</strong>.</p><p>All the Social media sites such as Twitter and Facebook are great examples of this pattern. You follow a user and when that user adds content, you along with all other followers of that user receive the notification. Other example includes RSS feeds and email subscription in which you have the option to follow or subscribe, and you receive the latest notification for the new feed.</p><h3>Observer Pattern JAVA Example</h3><p>Suppose we are building a cryptocurrency buy/sell application, which allows users to trigger the buy or sell process based on the notification received for price change events. For this example, I will have a few observers which will subscribe to a cryptocurrency. When the cryptocurrency price will be going down, the buyer observer will purchase some stocks. Similarly, in case of <a href="https://javarevisited.blogspot.com/2022/01/5-best-courses-to-learn-cryptocurrency.html">cryptocurrency </a>prices rise, seller observers will sell the stocks.</p><figure><a href="https://javarevisited.blogspot.com/2022/01/5-best-courses-to-learn-cryptocurrency.html"><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jOA_ZAql32zww5rw" /></a><figcaption>Photo by <a href="https://unsplash.com/@unarchive?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><h4>Subject Definition</h4><p>In the Subject interface, there are three methods declared. <strong>addObserver</strong> method is for adding subscribers, the <strong>removeObserver</strong> method is for deleting the existing subscriber and the <strong>notifyObservers</strong> method is for sending notifications to all subscribers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/23290d720b30d5a88688c4a2cd6d43a0/href">https://medium.com/media/23290d720b30d5a88688c4a2cd6d43a0/href</a></iframe><h4>Concrete Subject</h4><p>For concrete Subject, I have created a <strong>CryptoCurrency</strong> class with all the implemented methods from the <strong>Subject</strong> interface along with new fields for the name and price of the cryptocurrency.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3332ebb59a45dc46439dabd9296a0c7/href">https://medium.com/media/b3332ebb59a45dc46439dabd9296a0c7/href</a></iframe><h4>Observer Definition</h4><p>In the <strong>Observer</strong> interface, there is only a single method declared <strong>notification</strong>, which will be invoked by the concrete subject.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df861b66c4bdab19e9585d1b724a6e2e/href">https://medium.com/media/df861b66c4bdab19e9585d1b724a6e2e/href</a></iframe><h4>Concrete Observers</h4><p>For concrete observers, I have created 3 classes. <strong>PriceWatcher</strong> class is created to tell the current and previous price of updating <strong>CryptoCurrency</strong> concrete subject. <strong>CryptoCurrencyBuyer</strong> class is created for calling external API to buy cryptocurrency if the currency is reaching below a certain amount. Similarly, <strong>CryptoCurrencySeller</strong> class is created for calling an external API to sell cryptocurrency if the currency is reaching above a certain amount.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0458f90e2e3770dca653b8908cfb3124/href">https://medium.com/media/0458f90e2e3770dca653b8908cfb3124/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33209d9020cf9061753ad374634172d6/href">https://medium.com/media/33209d9020cf9061753ad374634172d6/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f896ba3faf210b9333a87246c02495e/href">https://medium.com/media/3f896ba3faf210b9333a87246c02495e/href</a></iframe><h4>Observer Pattern in Action</h4><p>In the demo code below, created a Bitcoin and five observers. All the subscribers are notified when the bitcoin price is updated.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8c5a8d000a9e2ee6a1e91a8c0dad4a5/href">https://medium.com/media/c8c5a8d000a9e2ee6a1e91a8c0dad4a5/href</a></iframe><p>Source Code Available at: <a href="https://github.com/s3c-d43m0n/Desing-Patterns-in-JAVA/tree/main/Behavioral/Observer">https://github.com/s3c-d43m0n/Desing-Patterns-in-JAVA/tree/main/Behavioral/Observer</a></p><h3>Key Points in the Implementation</h3><ul><li>Here <strong>Subject</strong> and <strong>Observer</strong> are interface. But It can be an abstract class as well, not bound to use interface only.</li><li><strong>Concrete Subject</strong> needs to maintain all the <strong>Observers</strong> in a <strong>collection</strong> as per the requirement. Here I have used <strong>CopyOnWriteArrayList</strong> (Fail-Safe) collection to store all observers as I am having some of the <strong>Observers</strong> which are going to remove themself while being iterated in the <strong>notifyObservers</strong> method.</li><li>Need to call <strong>notifyObservers</strong> method whenever there is a change in the state of <strong>Concrete Subject</strong>.</li><li>Each <strong>Concrete Observer</strong> needs to implement <strong>notification</strong> method for the action to take based on its requirement to consume the changes in <strong>Subject</strong>.</li><li>For each <strong>Concrete Observer</strong>, need to attach with <strong>Subject</strong> using <strong>addObserver</strong> method and detach using <strong>removeObserver</strong> method.</li></ul><p><em>What’s your favorite design pattern or if you’d like to understand better any other pattern or topic, feel free to reach out to me on </em><a href="https://www.linkedin.com/in/ritvik92/"><em>LinkedIn</em></a><em> or </em><a href="https://forms.gle/XFsuo1ZbP35gfqAX7"><em>Google Form</em></a><em> and I’ll try to cover it next time!</em></p><p><em>Please share this with all your Medium friends and hit that👏 button below to spread it around even more. Please follow </em><a href="https://medium.com/@ritvik.singh.chauhan"><em>me</em></a><em> for future updates. Thanks for reading.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17355b138329" width="1" height="1" alt=""><hr><p><a href="https://medium.com/javarevisited/java-developer-guide-to-start-with-observer-design-pattern-17355b138329">JAVA Developer Guide to start with Observer Design Pattern</a> was originally published in <a href="https://medium.com/javarevisited">Javarevisited</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>