# Builder Design Pattern

The Builder design pattern is a creational pattern, similar to the [Factory pattern](/content/design-patterns/factory-method-pattern/index.html) (Factory Method, Abstract Factory). Unlike the Factory pattern, which typically only offers one method for creating an object, the Builder pattern offers multiple methods that can be used to gradually define the characteristics of the type to be created. This provides a more flexible interface than a single method with a large number of parameters or a complex parameter object.

A typical builder design (to create _SomeType_) has the following characteristics:

- Named _SomeType_ Builder to communicate the use of the pattern
- Initializes a simple (or default) private instance of _SomeType_ upon construction
- Exposes methods that set properties on the private _SomeType_ instance

- Each method returns this, the _SomeTypeBuilder_ instance
- Exposes a Build (or Create) method that simply returns the private _SomeType_ instance

- In some cases where creating _SomeType_ is expensive, construction may be deferred to this step
- Optionally, expose (static) methods for getting known common configurations of _SomeType_

## A simple example in C#

```csharp
public class AddressBuilder
{
  private Address _address = new Address();

public AddressBuilder WithStreet(string street)
  {
    _address.Street = street;
    return this;
  }

public AddressBuilder WithState(string state)
  {
    _address.State = state;
    return this;
  }

// additional WithWhatever methods

public Address Build()
  {
    return _address;
  }
}
```
