<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Thomas Noe</title>
    <description>The latest articles on DEV Community by Thomas Noe (@t3h2mas).</description>
    <link>https://dev.to/t3h2mas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F184047%2F0824c387-14ee-4c05-bfa8-ed1884e44b7b.png</url>
      <title>DEV Community: Thomas Noe</title>
      <link>https://dev.to/t3h2mas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/t3h2mas"/>
    <language>en</language>
    <item>
      <title>Fluent Builder with JavaScript</title>
      <dc:creator>Thomas Noe</dc:creator>
      <pubDate>Tue, 09 Jun 2020 00:00:00 +0000</pubDate>
      <link>https://dev.to/t3h2mas/fluent-builder-with-javascript-54d4</link>
      <guid>https://dev.to/t3h2mas/fluent-builder-with-javascript-54d4</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.t3h2mas.xyz%2Fimages%2Ffluent-builder%2Fconstruction.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.t3h2mas.xyz%2Fimages%2Ffluent-builder%2Fconstruction.jpg" alt="construction"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Photo by Scott Blake on Unsplash&lt;/p&gt;



&lt;h2&gt;
  
  
  Experimenting with implementing the fluent builder pattern in JavaScript.
&lt;/h2&gt;

&lt;p&gt;The fluent builder pattern is a composition of the builder pattern and the fluent interface pattern.&lt;/p&gt;

&lt;p&gt;It’s a pattern that holds our hand through the maze of object construction.&lt;/p&gt;

&lt;p&gt;Our implementation uses es6 classes to give us something resembling a fluent builder.&lt;/p&gt;

&lt;p&gt;Traditionally fluent interfaces are built using… interfaces.&lt;/p&gt;

&lt;p&gt;Vanilla JavaScript doesn’t have interfaces. We’re left to do what we can with what we have.&lt;/p&gt;

&lt;p&gt;(This is where someone says something about &lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt;. Have at it, but I never said I was writing about TypeScript. However, I would be delighted to see someone implement their own Fluent Builder in TypeScript or your language of choice)&lt;/p&gt;

&lt;p&gt;For the curious, here is my &lt;a href="https://gist.github.com/t3h2mas/37c80de8b5c644f94702cf2bd61c2aec" rel="noopener noreferrer"&gt;attempt&lt;/a&gt; at implementing the pattern using JSDOC interfaces. I changed approaches after I realize that editor behavior was different between implementations.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to build a burrito
&lt;/h2&gt;

&lt;p&gt;To get to where we’re going first we will have to take a look at the &lt;a href="https://en.wikipedia.org/wiki/Builder_pattern" rel="noopener noreferrer"&gt;builder pattern.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Wikipedia summarizes the pattern as&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The builder pattern is a design pattern designed to provide a flexible solution to various object creation problems in object-oriented programming.&lt;/p&gt;

&lt;p&gt;The intent of the Builder design pattern is to separate the construction of a complex object from its representation. It is one of the Gang of Four design patterns.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s right. We are about to attempt to apply an &lt;em&gt;object-oriented&lt;/em&gt; design pattern from a book[1] written in &lt;strong&gt;1984&lt;/strong&gt; to JavaScript in 2020. What a time to be alive!&lt;/p&gt;

&lt;p&gt;Anyway…&lt;/p&gt;

&lt;p&gt;Maybe we want to make a burrito… Relax, this isn’t a &lt;a href="https://www.chrisdone.com/posts/monads-are-burritos/" rel="noopener noreferrer"&gt;monad&lt;/a&gt; tutorial&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Everyone loves Burritos
 */
class Burrito {
/**
 * @param {string} protein
 * @param {string} carb
 * @param {?string} salsa
 * @param {?string} cheese
 */
constructor(protein, carb, salsa, cheese) {
    // required toppings
    this.protein = protein;
    this.carb = carb;
    // optional toppings
    this.salsa = salsa;
    this.cheese = cheese;
  }
}

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

&lt;/div&gt;



&lt;p&gt;Our take on a burrito has the following properties required in the constructor&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a carb(ohydrate) such as brown or white rice&lt;/li&gt;
&lt;li&gt;a protein such as shredded pork or beef&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following are optional (for whatever reason)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a salsa of some variety&lt;/li&gt;
&lt;li&gt;cheese, queso, that ripe, runny, young or old fromage&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Making (or constructing) a burrito as shown could look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const burrito = new Burrito(
  "brown rice",
  "shredded pork",
  "green salsa",
  "cojita"
);
// do stuff to the burrito

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

&lt;/div&gt;



&lt;p&gt;If this burrito gets popular somehow we’re going to have to continue to make more and more burritos. Passing parameter after parameter in the same order to our &lt;code&gt;Burrito.constructor&lt;/code&gt; [2]&lt;/p&gt;

&lt;p&gt;We pass the parameters at the same time to construct the class instance.&lt;/p&gt;

&lt;p&gt;To be annoyingly repetitive, using individual parameters got the job done, but have implications such as&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;all parameters must be passed at the same time&lt;/li&gt;
&lt;li&gt;each parameter must be passed in the correct order&lt;/li&gt;
&lt;li&gt;the constructor definition grows with each new parameter passed [3]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we will attempt to bypass these implications using a builder… (The burrito in the following snippet is the same one we looked at before.)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * Everyone loves Burritos
 */
class Burrito {
  /**
   * @param {string} protein
   * @param {string} carb
   * @param {?string} salsa
   * @param {?string} cheese
   */
  constructor(protein, carb, salsa, cheese) {
    // required toppings
    this.protein = protein;
    this.carb = carb;
    // optional toppings
    this.salsa = salsa;
    this.cheese = cheese;
  }
}

/*
 * BurritoBuilder adds flexibility to burrito construction
 */
class BurritoBuilder {
  constructor() {
    this.toppings = {}; // 1
  }

  // 2
  /**
   * Add a protein to burrito
   * @param {string} protein
   * @returns {BurritoBuilder}
   */
  withProtein(protein) {
    this.toppings.protein = protein;
    return this; // 3
  }

  /**
   * Add a carbohydrate to burrito
   * @param {string} carb
   * @returns {BurritoBuilder}
   */
  withCarb(carb) {
    this.toppings.carb = carb;
    return this;
  }

  /**
   * Add salsa to our burrito
   * @param {salsa} salsa
   * @returns {BurritoBuilder}
   */
  withSalsa(salsa) {
    this.toppings.salsa = salsa;
    return this;
  }

  /**
   * Add cheese to our burrito
   * @param {string} cheese
   * @returns {BurritoBuilder}
   */
  withCheese(cheese) {
    this.toppings.cheese = cheese;
    return this;
  }

  // 4
  /**
   * Wrap our toppings into a finished burrito
   * @returns {Burrito}
   */
  build() {
    const { protein, carb, cheese, salsa } = 
    this.toppings;
    return new Burrito(protein, carb, cheese, salsa);
  }
}

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

&lt;/div&gt;



&lt;p&gt;There is a lot to unpack from our builder implementation! Let’s break down a few key points&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We store toppings in an object as a class property&lt;/li&gt;
&lt;li&gt;Topping adding methods follow the pattern of &lt;code&gt;.with[ToppingName]&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We return a reference to the instance of the Burrito Builder after adding each ingredient&lt;/li&gt;
&lt;li&gt;Finally, we have a build method that will attempt to build a burrito using the toppings we selected. This method &lt;a href="https://pics.me.me/that-rug-really-tied-the-room-together-the-big-lebowski-24483025.png" rel="noopener noreferrer"&gt;ties the room together&lt;/a&gt; by providing a tortilla wrapped resolution&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Enough with the lists, time to put our &lt;code&gt;BurritoBuilder&lt;/code&gt; to use!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const burrito = new BurritoBuilder()
  .withCarb("brown rice")
  .withSalsa("green")
  .withCheese("cojita")
  .withProtein("shredded pork")
  .build();

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

&lt;/div&gt;



&lt;p&gt;In this example we’re passing all the ingredients at once. We’re able to build a burrito in one statement by method chaining. Method chaining is one flavor found in builders and is available because we return a reference to the builder in every method besides the finalizing &lt;code&gt;build&lt;/code&gt;. (The &lt;code&gt;return this&lt;/code&gt; in each chain-able method allows us to chain, but we are still free to assign our burrito-to-be to a variable whenever we’d like.)&lt;/p&gt;

&lt;p&gt;We could easily do something in the spirit of 2020 era popular “healthy fast food” burrito joints&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CarbStation {
  static addIngredient(burrito, ingredient) {
    return burrito.withCarb(ingredient);
  }
}

class GrillStation {
  static addIngredient(burrito, ingredient) {
    return burrito.withProtein(ingredient);
  }
}

class ExtraStation {
  static addIngredient(burrito, category, ingredient) {
    if (category === "salsa") {
      return burrito.withSalsa(ingredient);
    }

    if (category === "cheese") {
      return burrito.withCheese(ingredient);
    }
    throw new Error("We don't sell that here!");
  }
}

class Cashier {
// oops, no register logic, free burritos
  static pay(burrito) {
    return burrito.build();
  }
}

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

&lt;/div&gt;



&lt;p&gt;Let’s recreate our burrito from before. Notice how we’re passing a burrito builder around from class to classso they can each add toppings with love and care. Construction of the burrito is delayed until we see fit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Warning, the following may offend you if you only speak const or point-free
const burritoBuilder = new BurritoBuilder(); // (reference #1)

let burritoWithCarb = CarbStation.addIngredient(burritoBuilder, "brown rice"); // (reference #2)
let burritoWithCarbAndProtein = GrillStation.addIngredient(
burritoWithCarb,
"shredded pork"
); // (reference #3)

ExtraStation.addIngredient(burritoWithCarbAndProtein, "guac", true);
ExtraStation.addIngredient(burritoWithCarbAndProtein, "salsa", "green salsa");
ExtraStation.addIngredient(burritoWithCarbAndProtein, "cheese", "cojita");
const readyToEatBurrito = Cashier.pay(burritoWithCarbAndProtein);

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

&lt;/div&gt;



&lt;p&gt;Notice a few things here.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We can reference our burrito mid-construction with chaining or by variable assignment&lt;/li&gt;
&lt;li&gt;We have 3 different variables (marked with comments) referencing the same thing&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;BurritoBuilder#build&lt;/code&gt; must be called when we’re ready to finalize our burrito build out&lt;/li&gt;
&lt;li&gt;We passed around an incomplete burrito builder. We called methods that independently added their own modifications.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So far we have briefly explored the second component of the term “fluent builder.” In true &lt;a href="https://en.wikipedia.org/wiki/LIFO" rel="noopener noreferrer"&gt;LIFO&lt;/a&gt; fashion, we will now look at the “fluent” component.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fluent interfaces
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://martinfowler.com/" rel="noopener noreferrer"&gt;Martin Fowler&lt;/a&gt; suggests that the term “&lt;a href="https://martinfowler.com/bliki/FluentInterface.html" rel="noopener noreferrer"&gt;fluent interface&lt;/a&gt;” is synonymous with an &lt;em&gt;internal&lt;/em&gt; &lt;a href="https://martinfowler.com/bliki/DomainSpecificLanguage.html" rel="noopener noreferrer"&gt;domain specific language&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In a summary of Fowler’s post, Piers Cawley poetically describes the fluent interface as a way to &lt;a href="https://bofh.org.uk/2005/12/21/fluent-interfaces/" rel="noopener noreferrer"&gt;“move [sic moving] object construction behind a thoughtful, humane interface."&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our implementation will be using classes to work around JavaScripts lack of interfaces.&lt;/p&gt;

&lt;p&gt;Without further ado, let’s introduce a plot twist so we can try to construct burritos behind a thoughtful, humane “interface.”&lt;/p&gt;

&lt;h3&gt;
  
  
  A wild boss appears
&lt;/h3&gt;

&lt;p&gt;You’re sitting at your keyboard when suddenly a wild boss appearsBoss &amp;gt; Your burrito code has been working for us so far but there’s a problem! When I presented the code to the client (Healthy Burrito Chain) they told us about some business rules we failed to discover in the original project specification!You &amp;gt; Oh no! Not surprise business rules!Boss &amp;gt; Instead of filing TPS reports on Saturday, you need to come in and make sure we enforce the following rules when creating burritos…&lt;/p&gt;

&lt;p&gt;(The rules the boss give you are as follows)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In order for a burrito to be built, it must have a carb and a protein. We cannot allow a burrito to be created without these ingredients.&lt;/li&gt;
&lt;li&gt;After the required ingredients are submitted, we must allow customers to either pay or add one or more extra ingredient.&lt;/li&gt;
&lt;li&gt;The extra ingredients are salsa, and cheese&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Oh No&lt;/em&gt; you think. It’s going to be a long weekend….&lt;/p&gt;

&lt;h3&gt;
  
  
  Saturday rolls around
&lt;/h3&gt;

&lt;p&gt;Instead of throwing out the decision to use the builder pattern for our burritos, maybe we can make some adjustments by making our builder &lt;em&gt;fluent&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Another way to look at our new business model by translating our burrito shop into a &lt;a href="https://en.wikipedia.org/wiki/Finite-state_machine" rel="noopener noreferrer"&gt;finite state machine&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.t3h2mas.xyz%2Fimages%2Ffluent-builder%2Fburrito-fsm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.t3h2mas.xyz%2Fimages%2Ffluent-builder%2Fburrito-fsm.png" alt="fluent builder finite state machine"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h4&gt;fluent builder finite state machine&lt;/h4&gt;



&lt;h3&gt;
  
  
  Shut up and show me the code
&lt;/h3&gt;

&lt;p&gt;Let us take our implementation, wrap it with some classes. Hopefully whatever comes out won’t make Mr. Fowler cringe.&lt;/p&gt;




&lt;p&gt;We’ll start with a class that allows us to set the protein.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ProteinSetter {
  /**
   * @param {BurritoBuilder} builder
   */
  constructor(builder) {
    // 1
    this.builder = builder;
  }

  /**
   * @param {string} protein
   * @returns {CarbSetter}
   */
  withProtein(protein) {
    // 2
    return new CarbSetter(this.builder.withProtein(protein));
  }
}

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

&lt;/div&gt;



&lt;p&gt;Notes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Our &lt;code&gt;ProteinSetter&lt;/code&gt; class takes our builder from before. We’re wrapping the existing builder class instead of replacing the implementation.&lt;/li&gt;
&lt;li&gt;We pass the builder to the &lt;code&gt;CarbSetter&lt;/code&gt; class after choosing a protein.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;code&gt;CarbSetter&lt;/code&gt; class looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CarbSetter {
  /**
   * @param {BurritoBuilder} builder
   */
  constructor(builder) {
    this.builder = builder;
  }

  /**
   * @param {string} carb
   * @returns {ExtraSetter}
   */
  withCarb(carb) {
    return new ExtraSetter(this.builder.withCarb(carb));
  }
}

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

&lt;/div&gt;



&lt;p&gt;This class is pretty similar to the &lt;code&gt;ProteinSetter&lt;/code&gt; we just saw. After the carb is set, we pass our builder along to the &lt;code&gt;ExtraSetter&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Are you starting to see the pattern here? We return class instances to control the flow of burrito construction.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;ExtraSetter&lt;/code&gt; class looks like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ExtraSetter {
  /**
   * @param {BurritoBuilder} builder
   */
  constructor(builder) {
    this.builder = builder;
  }

  /**
   * @param {number} salsa
   * @returns {ExtraSetter}
   */
  withSalsa(salsa) {
    this.builder.withSalsa(salsa);
    return this;
  }

  /**
   * @param {string} cheese
   * @returns {ExtraSetter}
   */
  withCheese(cheese) {
    this.builder.withCheese(cheese);
    return this;
  }

  /**
   * @returns {Burrito}
   */
  wrapUp() {
    return this.builder.build();
  }
  }

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

&lt;/div&gt;



&lt;p&gt;Just like the other classes that we’ve seen, except for one crucial detail. The &lt;code&gt;ExtraSetter&lt;/code&gt; can complete a build.&lt;/p&gt;

&lt;p&gt;Our extra setter can:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add optional toppings in any order&lt;/li&gt;
&lt;li&gt;Complete the construction of our tortilla wrapped master piece&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This last class is our entry point to the fluent &lt;em&gt;burrito&lt;/em&gt; builder work flow.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * FluentBuilder to use as a starting point
 */
class FluentBuilder {
  static onTortilla() {
    return new ProteinSetter(new BurritoBuilder());
  }
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Drum roll, please
&lt;/h2&gt;

&lt;p&gt;Now for the moment we’ve all been waiting for…&lt;/p&gt;

&lt;p&gt;We can use our Fluent Builder as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const burrito = FluentBuilder.onTortilla()
  .withProtein("a")
  .withCarb("brown rice")
  .withCheese("cojita")
  .wrapUp();

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

&lt;/div&gt;



&lt;p&gt;This is valid usage. Most editors will &lt;em&gt;guide&lt;/em&gt; us down this path. Unlike the &lt;code&gt;BurritoBuilder&lt;/code&gt; we can only call the methods that were intentionally exposed at any particular stage.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.t3h2mas.xyz%2Fimages%2Ffluent-builder%2Fbuild-small.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.t3h2mas.xyz%2Fimages%2Ffluent-builder%2Fbuild-small.gif" alt="Fluent Builder in action"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h4&gt;Fluent Builder in action&lt;/h4&gt;



&lt;p&gt;We’re forced down the happy path.&lt;/p&gt;

&lt;p&gt;Go ahead, try it. Try to create a burrito using the &lt;code&gt;FluentBuilder&lt;/code&gt; methods without adding a protein. That’s right, you can’t without directly accessing the builder (which is totally cheating)&lt;/p&gt;

&lt;h2&gt;
  
  
  I love it, how can I &lt;em&gt;use&lt;/em&gt; it?
&lt;/h2&gt;

&lt;p&gt;Personally I’ve been using Fluent Builders to constrain the construction of &lt;a href="https://martinfowler.com/eaaCatalog/dataTransferObject.html" rel="noopener noreferrer"&gt;DTO&lt;/a&gt;s in tests and the application layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback
&lt;/h2&gt;

&lt;p&gt;Yes please &lt;a href="https://twitter.com/teh2mas" rel="noopener noreferrer"&gt;@teh2mas&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;[1] &lt;a href="https://en.wikipedia.org/wiki/Design_Patterns" rel="noopener noreferrer"&gt;https://en.wikipedia.org/wiki/Design_Patterns&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[2] A common pattern JavaScript is to pass multiple parameters into a class constructor, method, or function as an object like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Burrito({ carb, protein, salsa, cheese }) { /* ... */ }

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

&lt;/div&gt;



&lt;p&gt;Which is a fine way of taking advantage of destructuring. We are also free to pass the parameters in whichever order we’d like.&lt;/p&gt;

&lt;p&gt;[3] This can be a &lt;a href="https://martinfowler.com/bliki/CodeSmell.html" rel="noopener noreferrer"&gt;code smell&lt;/a&gt; hinting at a chance to decompose our class into smaller components&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>builderpattern</category>
      <category>fluentbuilder</category>
      <category>designpatterns</category>
    </item>
  </channel>
</rss>
