Builder pattern allows the instantiation of a complex object in a step by step manner. For example, in Ruby, we could do this:
class Person
attr_accessor :first_name, last_name, :age
def initialize(&blk)
instance_eval(&blk) if block_given?
end
end
person = Person.new do
self.first_name = 'Nithin'
self.last_name = 'Bekal'
self.age = 27
end
Real world use of builder pattern - Builder::XMLMarkup
Links