of an object. It is used when an object cannot be produced in one single step. § Builder isolates the product’s internal representation and the steps for the product’s construction. § Use the Builder pattern to get rid of having a Product with multiple constructors with a diverse number of parameters each, i.e., as an option for providing default values for attributes in an object.
// Delegate to several builders public class Client { public static void main( string[] args ) { Director director = new Director( ); StudentBuilder sBuilder = new StudentBuilder(); InstructorBuilder iBuilder = new InstructorBuilder(); director.constructStudent( sBuilder ); Student s = sBuilder.getResult(); s.show(); director.constructInstructor( iBiulder ); Instructor i = iBuilder.GetResult(); i.Show(); } }
salary; private String access; private int hours; private Computer c; // common simple trivial getters // common simple trivial setters // common simple trivial constructor // what about making the constructor private ? } class Instructor { private int salary; private String access; private int hours; private Computer c; // common simple trivial getters // common simple trivial setters // common simple trivial constructor // what about making the constructor private ? }