<?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 Jacob Cunningham on Medium]]></title>
        <description><![CDATA[Stories by Jacob Cunningham on Medium]]></description>
        <link>https://medium.com/@jacobcunningham?source=rss-3d859412bae5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*T28-O1viD_c4u-xHvGS3zA.jpeg</url>
            <title>Stories by Jacob Cunningham on Medium</title>
            <link>https://medium.com/@jacobcunningham?source=rss-3d859412bae5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:38:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jacobcunningham/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[Out with the Onion, in with Vertical Slices]]></title>
            <link>https://medium.com/@jacobcunningham/out-with-the-onion-in-with-vertical-slices-c3edfdafe118?source=rss-3d859412bae5------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3edfdafe118</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[software-design]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software]]></category>
            <dc:creator><![CDATA[Jacob Cunningham]]></dc:creator>
            <pubDate>Wed, 18 Jul 2018 03:22:17 GMT</pubDate>
            <atom:updated>2018-07-18T03:22:17.898Z</atom:updated>
            <content:encoded><![CDATA[<p>Vertical Slice Architecture is slowly becoming all the rage when given the opportunity for a new project or the chance for major refactoring of technical debt in legacy systems. So what are vertical slices? Why should you move away from the commonplace Onion Architecture? What are the motivations for the need of this new style of architecture? We’ll answer these questions and more as we explore Vertical Slice Architecture.</p><h3>What are Vertical Slices?</h3><blockquote>The term “vertical slice” refers to a cross-sectional slice through the layers that form the structure of the software code base.<br>- <a href="https://en.wikipedia.org/wiki/Vertical_slice">Wikipedia Vertical Slice Page</a></blockquote><p>This simply means that there exists a vertical slice of our application that runs from the user interface down to the deepest layer in our application such as the data access layer. These vertical slices exist for each command and/or query that exists within an application.</p><p>An example application that implements vertical slices could be an e-commerce web application built with .NET MVC and React. In this imaginary web application, we have a bit of functionality where a user can add a product to a favorite’s list. A vertical slice exists for this functionality where it would run from the client side React code, where the user clicks a button to add the product, down to the database layer, where the product is added to a favorite product’s table in the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*JHlN7ixDbPFgyjZh1GQIFQ.png" /><figcaption>Figure 1. High level view of vertical slice architecture.</figcaption></figure><h3>Okay, that’s great and all, but why?</h3><ul><li>The code for each vertical slice (or feature) lives within its own namespace (or feature folder).</li><li>Less of a need to develop abstractions as the code for each vertical slice is very specific and so there’s not much of a need to develop services, repositories, factories, etc within a vertical slice.</li><li>By isolating our vertical slices, each slice can take the optimal approach to accomplishing the request. For example, if the request deals with data access, our vertical slice could do so by using an ORM while another vertical slice uses a different method such as using a stored procedure.</li><li>Context switching becomes less of a problem as everything related to that feature is in the current namespace. There’s no need to follow code down a rabbit hole across the application.</li><li>Change requests from users or the business tend to be vertical in manor, so it makes sense to architect our application vertically as well. It is not often that you get a change request for something that is horizontal in nature.</li></ul><h4>Things to look out for</h4><ul><li>Vertical slices should be isolated. One vertical slice should not reach outside of it’s namespace and it should definitely not call into another vertical slice.</li><li>Code duplication is very likely as it is very possible that one vertical slice will have the need for the same business logic as another vertical slice. This can be fixed by pushing this business logic into a domain object or extension method.</li></ul><h3>How About an Example?</h3><p>I know if you’re like me, then you like visuals and examples. Let’s take a look at an example of a folder structure for some vertical slices.</p><pre>- Features<br>  - Products<br>    - AddFavoriteProduct<br>      - AddFavoriteProductController<br>      - AddFavoriteProductCommand<br>      - AddFavoriteProductResponse<br>      - AddFavoriteProductCommandHandler<br>      - AddFavoriteProductContainer.js<br>      - AddFavoriteProduct.js<br>      - AddFavoriteProduct.css<br>    - GetProductList<br>      - GetProductListController<br>      - GetProductListQuery<br>      - GetProductListResponse<br>      - GetProductListCommandHandler<br>      - GetProductListContainer.js<br>      - GetProductList.js<br>      - GetProductList.css</pre><p>This visual really makes it all come together, right? You can really see the benefits that you’ll be gaining by keeping all code related to a feature in close proximity.</p><p><strong><em>Are we really not going to talk about the fact that there’s front-end code mixed in with the back-end code?</em></strong></p><p>I know, I know. That was my first reaction, too, when I first saw vertical slices spanning through to and including the UI (my initial introduction to vertical slices was limited to server-side code). If you think about it for a second, though, it does make sense. By including the front-end code in the same folder as the back-end code relevant to that feature, we gain all the benefits mentioned above, but most importantly the benefit of file proximity. This is especially beneficial if your development team is not split between front-end and back-end developers.</p><p><strong><em>Wait! My development team is split between front-end and back-end developers</em></strong></p><p>This is not a hard and fast rule that you must keep all code, both front-end and back-end, together in this same folder. If it makes more sense to make a split at the front-end and back-end, where the back-end code implements vertical slices, but giving front-end developers the freedom to implement features by pages or develop vertical slices of their own, or some other strategy, that is okay!</p><h3>Let’s Wrap It Up</h3><p>We’ve talked about what exactly vertical slices are and how they fit into application development. We also mentioned benefits for implementing this style of architecture such as close file proximity and choosing the best approach to do a particular job. I highly recommend you give vertical slice architecture a shot on your next greenfield application, or try it out as a proof of concept for the system that you are maintaining today.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3edfdafe118" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Fluent Builder Pattern]]></title>
            <link>https://medium.com/@jacobcunningham/the-fluent-builder-pattern-ac1b6c23afc3?source=rss-3d859412bae5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac1b6c23afc3</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Jacob Cunningham]]></dc:creator>
            <pubDate>Fri, 15 Jun 2018 20:35:29 GMT</pubDate>
            <atom:updated>2018-06-15T20:35:29.721Z</atom:updated>
            <content:encoded><![CDATA[<p>You have probably heard of the builder pattern before and I’ll bet that you have seen it in its <a href="https://en.wikipedia.org/wiki/Builder_pattern">classic representation</a>. While that will get you what you want, I find that the classic representation isn’t as intuitive as the fluent representation of the builder pattern that I’ve come across in the past.</p><p><strong><em>What isn’t intuitive about the classic builder pattern?</em></strong></p><p>In the C# example of the classic builder pattern from the link above, they are building a director class as well as a very specific builder class. Inside these specific builder classes, they are hard coding the values to be used to build their object. Why? Why should I need to create a new builder class for every minor variation of the object that I want to create? In my experience, I am usually getting input from a user to use to build an object. Also, what is this director class all about? Why can’t that logic be encapsulated inside the builder itself?</p><h4>Whats the point?</h4><p>Why should someone use the builder pattern? What are the benefits of it? That’s easy. Whether you are using the classic builder pattern or some other implementation, you will be gaining these benefits:</p><ul><li>Centralization of the object creation code</li><li>Control over the order that the creation steps are executed</li><li>Build different representations of an object with the same creation process</li><li>Reduce object constructor complexity</li></ul><p>Still not convinced that these benefits are worth the implementation of the builder pattern in your application? Let’s take a look at a couple examples of creating an object without the builder pattern.</p><p><strong>Example 1</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5017b510406ccedf07d5b645084264ce/href">https://medium.com/media/5017b510406ccedf07d5b645084264ce/href</a></iframe><p>The first example, shown above, is an example where we are instantiating an object by calling an empty constructor and setting the object’s public properties directly. You might think that this looks clean. So what are the fall backs of this approach? While this example is simplistic in nature, we could reason that we have two issues with this method of object creation.</p><ul><li>Unable to mark certain properties as required and others as optional</li><li>Object creation code is not consolidated into one place, meaning our object could be created differently in different areas of the application</li></ul><p><strong>Example 2</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ce4296fe63cc5de14d8d508409acdfb/href">https://medium.com/media/8ce4296fe63cc5de14d8d508409acdfb/href</a></iframe><p>The second example, shown above, is an example where we are passing in all of our values to the constructor. While this does solve the issue we had in Example 1 with required and optional fields, we still have one problem with this method. That problem being, with so many constructor parameters of the same datatype back-to-back, it would be easy for a developer to pass the wrong value to the wrong parameter.</p><p>I hope by now you are convinced that we need to do something to help us with object creation. This is where the builder pattern comes into play as it is a popular candidate for object creation and solves the problems that we had in the above two examples.</p><h4>The Players</h4><p>Before jumping into the fluent implementation of the builder pattern, we must first understand the players that are involved that allow the pattern to come to life. There are three players involved with the builder pattern; they include <em>the object</em>, <em>the object builder</em>, and <em>the object builder interface(s). The object </em>is exactly what it sounds like, it is the object that we are wanting to create. <em>The object builder</em> is the object that contains all of the creation logic to produce <em>the object.</em> And finally, <em>the object builder interface(s)</em> are the interfaces that will be implemented by <em>the object builder.</em> These interfaces are what allow for <em>the object builder</em> to be written fluently while handling required and optional fields nicely.</p><h4>Step 1: Creating our Object</h4><p>We first must have <em>the object</em> that we are trying to build. This is the easy part as in most cases we already have<em> the object</em> and we are simply looking to implement the builder pattern as an easier way to create this hard-to-create object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea1d2a4cfa858525f2147287604ed35b/href">https://medium.com/media/ea1d2a4cfa858525f2147287604ed35b/href</a></iframe><h4>Step 2: Creating the Object Builder Interface(s)</h4><p>Here, we will define a few interfaces that will be implemented by the <em>object builder.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f754483b9663e50eccd1336e0ed45218/href">https://medium.com/media/f754483b9663e50eccd1336e0ed45218/href</a></iframe><p>It is important to take notice of the ordering of the interfaces. The first interface we have is ICustomerName which has a method with a return type of ICustomerPhoneNumber which is the second interface we have defined. By following this pattern, we can enforce required fields to be entered in one at a time.</p><p><strong><em>What about optional fields?</em></strong></p><p>Skip to the last interface we have defined, ISalesOrderOptionalValues. This interface contains all of the method signatures for optional fields as well as a method to finish off the builder and return <em>the object.</em></p><h4>Step 3: Creating the Object Builder</h4><p>In this step, we are going to create the class that will become <em>the object builder</em>. To start off with, this builder class contains two important functional components: a private constructor and a public static method that will return a new instance of <em>the object builder</em> itself<em>.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fc1b7d18568a6dea5c34caf194d1d65/href">https://medium.com/media/4fc1b7d18568a6dea5c34caf194d1d65/href</a></iframe><p>It is important to note that our static Start() method, the method that we will call to start building <em>the object</em>, will return a concrete implementation of the ICustomerName interface. If we look back at our interface definitions, we will see that this forces us to supply a value for the customer’s name.</p><p><strong><em>Why mark the constructor private if we are simply going to create a public static method to return a new instance of the object builder anyway?</em></strong></p><p>This is mostly a coding style preference. We will not be using <em>the object builder</em> for anything other than creating <em>the object</em>. With that in mind, there’s no need for us to new up <em>the object builder</em> ourselves. We can simply call the static method and off we go building <em>the object.</em></p><h4>Step 4: Implementing the Builder Interfaces</h4><p>Implementing the builder interface(s) is quite straightforward. We simply create private instance variables in <em>the object builder</em> class to temporarily hold the values that will eventually be used to create <em>the object</em> in the Finish() method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9dd9d74e7839bf28dea50776ee30a663/href">https://medium.com/media/9dd9d74e7839bf28dea50776ee30a663/href</a></iframe><h4>Using our Builder</h4><p>Our builder is now ready to be used! We simply call the static Start() method to start building our object, and using our IDE’s intellisense we can see what is the next required (or optional) field that we need to supply to <em>the object builder.</em> We finish off building and returning <em>the object</em> by calling the Finish() method.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fe96de0bb6b0bdd6063511f8447117d/href">https://medium.com/media/6fe96de0bb6b0bdd6063511f8447117d/href</a></iframe><p>See the <a href="https://dotnetfiddle.net/">dotnetfiddle</a> below for an interactive example!</p><p><a href="https://dotnetfiddle.net/4e3eYy">Fluent Builder Example | C# Online Compiler | .NET Fiddle</a></p><h4>When to use the Builder Pattern</h4><p>There is at least two code smells to look out for when determining if the builder pattern is right for you: telescoping constructors and if the object that you’re creating can have different representations, but is built with the same creation logic.</p><p>Telescoping constructors are when you have multiple constructors, each to handle a specific scenario to create the object. Typically, each of these constructors will eventually call a default constructor.</p><p>If the object that you’re creating is always created in the same way, but sometimes with a different set of inputs, then the builder pattern might be a good idea. Take our sales order as an example, we want to always create a sales order in the same way, but the details of the order will most likely be different for each sales order. The builder pattern will also help to centralize the creation logic to ensure that we are creating our object the same way everywhere.</p><p><strong><em>What if I want to build an object by mapping fields from one object to another?</em></strong></p><p>One of the main reasons that you would introduce the builder pattern (also listed in the benefits section) is to centralize complex object creation code. Mapping fields from one object to another is not all that complicated and so the builder pattern will likely be overkill for such a task. If mapping is beginning to become a burden to your application, then you should look into libraries such as <a href="https://github.com/AutoMapper/AutoMapper">AutoMapper</a>.</p><h4>Summary</h4><p>That wasn’t too hard, was it? We simply created <em>the object</em> that we wanted, and by using <em>the object builder</em> that implemented specially crafted <em>builder interface(s) </em>we were able to gain these benefits:</p><ul><li>Centralization of the object creation code</li><li>Control over the order that the creation steps are executed</li><li>Build different representations of an object with the same creation process</li><li>Reduces object constructor complexity</li></ul><p>We achieved these benefits by:</p><p>Centralizing the logic of object creation into one place. Now if we ever need to modify how our object is created, we don’t have to track down every place that object is created, but just modify the builder class.</p><p>Since we have our object code centralized into one place, we can now easily control the order in which the creations steps are being executed. An example of this is in the Finish() method of our SalesOrderBuilder.</p><p>As we mentioned earlier, we always want to build our sales order in the same way, but usually with different inputs coming from the user. This is exemplified in our SalesOrderBuilder where our methods have parameter(s) whose values can be different per sales order.</p><p>And finally, we’ve reduced the constructor complexity by moving that logic into the SalesOrderBuilder itself. The constructor logic is split among the builder methods and the Finish() method.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac1b6c23afc3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>