What
is the need for Bridge Pattern in C#?
You can use
Builder pattern if you want to separate abstraction and implementation
of your program so that they can be maintained independently.
Here is a code sample for it:
class sampleAbstraction
{
protected sampleImplementation impObj;
public sampleImplementation ImpObj {
set { impObj = value;}
}
public virtual void sampleMethod() {
impObj.sampleMethod();
}
}
class sampleImplementation {
public virtual void sampleMethod() {
Console.WriteLine(Executing sampleMethod of sampleImplementation);
}
}
class derivedAbstraction : sampleAbstraction {
public override void sampleMethod() {
impObj.sampleMethod();
}
}
public class testClass {
public static void Main() {
abstractionPart absObj = new derivedAbstraction();
absObj.ImpObj = new sampleImplementation();
absObj.sampleMethod();
}
}
|