<?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 Deepak Bapat on Medium]]></title>
        <description><![CDATA[Stories by Deepak Bapat on Medium]]></description>
        <link>https://medium.com/@deepakbapat?source=rss-3717eed787c8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OBUgNOt6gXJqmU-x3lUL6A.jpeg</url>
            <title>Stories by Deepak Bapat on Medium</title>
            <link>https://medium.com/@deepakbapat?source=rss-3717eed787c8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 12:48:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@deepakbapat/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[The Pipeline design pattern (in Java)]]></title>
            <link>https://medium.com/@deepakbapat/the-pipeline-design-pattern-in-java-831d9ce2fe21?source=rss-3717eed787c8------2</link>
            <guid isPermaLink="false">https://medium.com/p/831d9ce2fe21</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Deepak Bapat]]></dc:creator>
            <pubDate>Wed, 16 Jan 2019 23:17:22 GMT</pubDate>
            <atom:updated>2019-01-17T13:51:30.886Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently on a project, I was looking to break down a large operation into separate pieces that could be tested and executed independently. The operation itself was complex to the point where it had become unmanageable; each successive update to the operation was adding regressions to the code. In addition, each update required the developer to write a large number of unit tests to check many permutations of inputs. This piece of the codebase was eating up the most developer time to maintain.</p><p>I tried refactoring the operation using instance methods that all lived within the operation’s class, so that the operation would be a series of successive method calls, but this didn’t quite “fit” right. Even moving each of the instance methods into it’s own helper class felt like it wasn’t the right code organization. There were many exceptions being thrown in the code (I’m a huge proponent of the <strong>Clean Code</strong> by <strong>Robert C. Martin</strong>) and trying to find the called methods inside bloated try-catch handlers became difficult.</p><p>I tried to look through Design Patterns online, specifically those that were created by the <strong>Gang of Four </strong>(you can search this term), and the closest thing I could find was the <strong>Chain of Responsibility</strong> pattern. However, the classic version of this pattern would have required me to mutate the input at each step. What I wanted was something more <strong>Functional</strong>, where inputs were immutable and each step would output a result to be used by the next step (similar to Java streams for collections). Thankfully I managed to stumble upon <a href="https://stackoverflow.com/questions/39947155/pipeline-design-pattern-implementation">this stackoverflow post</a>, that brought me a solution.</p><p>So here is the Pipeline Design Pattern in Java, pulling from elements of functional programming and making use of Java 8 lambdas.</p><p>The interface that each “step” of the Pipeline implements:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a42db24e9b970052e47f2cdb117553b1/href">https://medium.com/media/a42db24e9b970052e47f2cdb117553b1/href</a></iframe><p>This is followed by the actual “pipeline” which runs each step in series, using the output of one for the input of the next step:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b9b9567657dd82f4a083da9dadc2f67/href">https://medium.com/media/4b9b9567657dd82f4a083da9dadc2f67/href</a></iframe><p>Let’s now take an example. Suppose we wanted to take two integers, add them together, and return the string representation of the result. The code might look as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9080e1e314ba75bc055689c8e1979b7/href">https://medium.com/media/e9080e1e314ba75bc055689c8e1979b7/href</a></iframe><p>There are some caveats to the <strong>Pipeline design pattern</strong>.</p><ul><li>The pattern can lead to over architecting the inputs and output. It is a ton of work in java to create the inputs and outputs needed for a very complex pipeline. However, I feel that creating the inputs and outputs makes you think about what each step is ingesting. I’ve found that my steps are broken into better, more modular (and testable) pieces versus an more iterative approach.</li><li>There will be initial input values that need to be passed to each output for each step because they are not used until later in the pipeline. This is ok, although for some people it may feel more disorganized.</li></ul><p>In my humble opinion, the <strong>Pipeline design pattern </strong>is a useful pattern for organizing complex operations in code where initial values get converted into intermediate values that get turned into final values. It takes really nice aspects of functional programming and brings it to more iterative OOP practices. I will definitely be using this pattern more often now that I’ve seen it work.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=831d9ce2fe21" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>