Separates the construction of a complex object from its representation so that the same construction process can create different representations.
package com.apwebco.patterns.gof.builder; // Builders public abstract class PromoKitBuilder { protected PromoKit promoKit = new PromoKit(); public abstract void buildVideoPart(); public abstract void buildGarmentPart(); public abstract void buildBookPart(); public abstract PromoKit getPromoKit(); } public class MenPromoKitBuilder extends PromoKitBuilder { public void buildVideoPart() { // add videos to PromoKit based on men-specific preferences } public void buildGarmentPart() { // add men garments to PromoKit } public void buildBookPart() { // add books to PromoKit based on men-specific preferences } public PromoKit getPromoKit() { return promoKit; } } public class WomenPromoKitBuilder extends PromoKitBuilder { public void buildVideoPart() { // add videos to PromoKit based on women-specific preferences } public void buildGarmentPart() { // add women garments to PromoKit } public void buildBookPart() { // add books to PromoKit based on women-specific preferences } public PromoKit getPromoKit() { return promoKit; } } // Director public class PromoKitDirector { public PromoKit createPromoKit(PromoKitBuilder builder) { builder.buildVideoPart(); builder.buildGarmentPart(); builder.buildBookPart(); return builder.getPromoKit(); } } // Integration with overal application public class Application { public static void main(String[] args) { String gendre = "M"; PromoKitDirector director = new PromoKitDirector(); PromoKitBuilder promoKitBuilder = null; if (gendre.equals("M")) { promoKitBuilder = new MenPromoKitBuilder(); } else if (gendre.equals("F")) { promoKitBuilder = new WomenPromoKitBuilder(); } else { // .... } PromoKit result = director.createPromoKit(promoKitBuilder); } }