# OPINION: Builder pattern is not explained correctly

**URL:** <https://forum.codewithmosh.com/t/opinion-builder-pattern-is-not-explained-correctly/8094>\
**Category:** Design Patterns\
**Created:** [October 23, 2021, 8:26am UTC](https://forum.codewithmosh.com/t/opinion-builder-pattern-is-not-explained-correctly/8094 "2021-10-23T08:26:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aderchox](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@aderchox](https://forum.codewithmosh.com/u/aderchox)\
**Post date:** [October 23, 2021, 8:26am UTC](https://forum.codewithmosh.com/t/opinion-builder-pattern-is-not-explained-correctly/8094/1 "2021-10-23T08:26:54Z")

</div>

Although Mosh’s course on Design Patterns is really great and I’d recommend it to everyone, I believe what he has taught as the Builder pattern is actually the Strategy pattern.

The correct explanation of the Builder pattern could be studied in the Joshua Bloch’s book which is obviously a pattern distinct from the Strategy pattern. Just wanted to share this, as it might spark in someone else’s mind too.

---

<div class="post-metadata">

**Author:** ![jmrunkle](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/jmrunkle/32/3765_2.png) [@jmrunkle](https://forum.codewithmosh.com/u/jmrunkle)\
**Post date:** [August 11, 2022, 1:48am UTC](https://forum.codewithmosh.com/t/opinion-builder-pattern-is-not-explained-correctly/8094/2 "2022-08-11T01:48:46Z")

</div>

What he describes is certainly not the way I feel like I have seen the Builder pattern during my years in this industry.

My experience with the Builder pattern is about turning something that takes a bunch of unnamed constructor parameters into a much more sensible fluent API for building up an object piece by piece (and ideally resulting in an immutable constructed object while the builder was mutable).

So imagine you have some class like this:

```auto
public class House {
  public House(
    int numWindows,
    int numDoors,
    int numFullBathrooms,
    boolean hasHalfBath,
    boolean smartLocks,
    boolean airConditioning) { ... }
}

```

Calling that constructor would look like this: `new House(5, 3, 2, true, false, true)`. That is almost completely illegible. But… if you use a Builder class, you can end up with a fluent situation like this:

```java
House.builder()
  .setNumWindows(5)
  .setNumDoors(3)
  .setNumFullBathrooms(2)
  .setHasHalfBath(true)
  .setSmartLocks(false)
  .setAirCondition(true)
  .build();

```

That is much easier to read. Usually the constructor for the House would be private and take the Builder class as input:

```java
public class House {
  public House(Builder) { ... }
  Builder builder() {
    return new Builder();
  }
  public static class Builder { ... }
}

```

That being said, what Mosh describes is much more similar to what the pattern is specifically described as. For example, here on Wikipedia:

> **[Builder pattern](https://en.wikipedia.org/wiki/Builder_pattern)**
>
> The builder pattern is a design pattern designed to provide a flexible solution to various object creation problems in object-oriented programming. 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.
> The Builder design pattern is one of the GoF design patterns that describe how to solve recurring design problems in object-oriented software.
> The Builder design pattern solves problems ...

It just does not match what my experience has been working with this pattern in practice. YMMV.
