public abstract class Builder { public abstract void showtitle(); public abstract void showbody(); }
public class Director { public void show(Builder b) { b.showtitle(); b.showbody(); } }
public class PageA : Builder { public override void showtitle() { Console.WriteLine( " PageA : title "); } public override void showbody() { Console.WriteLine( " PageA : body "); } }
public class PageB : Builder { public override void showtitle() { Console.WriteLine( " PageB : title "); } public override void showbody() { Console.WriteLine( " PageB : body "); } }
调用:
{ PageA a = new PageA(); PageB b = new PageB(); Director d = new Director(); d.show(a); d.show(b); }