[本文属原创,如有转载,请注明出处http://blog.csdn.net/yl02520/article/]
Chromium是一个复杂的开源项目,其中应用了丰富的设计模式来组织代码,应用最广泛的应该算是Delegate Pattern(委托模式)。
什么是委托模式?
根据维基百科的解释,委托模式就是在面向对象的编程中,某些类自己不执行一些任务,并把这些任务委托给另外一个类去执行,那么执行任务的类就被称为委托类。
下面是一个典型的Java实例(摘自点击打开链接):
class RealPrinter { // the "delegate"
void print() {
System.out.print("something");
}
}
class Printer { // the "delegator"
RealPrinter p = new RealPrinter(); // create the delegate
void print() {
p.print(); // delegation
}
}
public class Main {
public static void ma