enum ItemType { Weapon, Armor, Other } class Item { // lots of instance variables to set... private ItemType type; private String name; private int value; private int weight; private int strength; private char symbol; // the builder pattern uses a nested class called builder public static class Builder { // these two are required to be specified private ItemType type; private String name; // these are given default values private int value = 5; private int weight = 10; private int strength = 0; private char symbol = 'i'; // the required ones go into the Builder constructor public Builder(ItemType type, String name) { this.type = type; this.name = name; } // methods for setting each optional property public Builder value(int v) { value = v; return this; } public Builder weight(int w) { weight = w; return this; } public Builder strength(int s) { strength = s; return this; } public Builder symbol(char s) { symbol = s; return this; } // this method returns the completed Item object public Item build() { return new Item(this); } } // end of the nested Builder class // the only constructor takes the builder as parameter private Item(Builder builder) { // copy the things out of the Builder into the Item this.type = builder.type; this.name = builder.name; this.value = builder.value; this.weight = builder.weight; this.strength = builder.strength; this.symbol = builder.symbol; } // this is a regular Item method @Override public String toString() { return type.toString() + " " + name + " " + value + " " + weight + " " + strength + " " + symbol; } // more methods would go here... } public class BuilderExample { public static void main(String args[]) { // build some items this way Item sword = new Item.Builder(ItemType.Weapon, "Steel Sword") .symbol('s') .strength(15) .build(); Item armor = new Item.Builder(ItemType.Armor, "Iron cuirass") .value(12) .symbol('a') .strength(7) .weight(13) .build(); System.out.println(sword); System.out.println(armor); } }