Search This Blog

2009-06-28

Implementation of Builder Pattern

Builder pattern:Seperates object constructions from its representation.

using System;
using System.Collections.Generic;
using System.Text;

namespace BuilderPattern
{
interface IBuilder
{
void DoIt();
}
class BuilderA:IBuilder
{
public void DoIt()
{
Console.WriteLine("BuilderA is called");
}
}
class BuilderB : IBuilder
{
public void DoIt()
{
Console.WriteLine("BuilderB is called");
}
}
class Director
{
public void Construct(IBuilder builder)
{
builder.DoIt();
}
}
class Program
{
static void Main(string[] args)
{
Director d = new Director();
IBuilder build = new BuilderA();
d.Construct(build);
Console.ReadLine();
}
}
}

Output:

No comments: