好了,基于上述的分析,我们写出如下的伪代码:
class cpu_bus_driver ;
.......
virtual function cpu_bus_driver create_object();
cpu_bus_driver me ;
me = new ;
return me ;
endfunction
static virtual function cpu_bus_driver create();
cpu_bus_driver key;
key = new ;
new_driver = factory.create_object(factory.lookup(key));
return new_driver ;
endfunction
endclass
class new_cpu_bus_driver extends cpu_bus_driver;
.......
virtual function cpu_bus_driver create_object();
new_cpu_bus_driver me ;
me = new ;
return me ;
endfunction
static virtual function cpu_bus_driver create();
new_cpu_bus_driver key;
key = new ;
用key作为键字去factory的数据库中查出替换条目,得知想不需要替换
factory利用查得的结果,生成一个new_cpu_driver对象给我,叫做 new_driver
return new_driver ;
endfunction
endclass
class factory ;
cpu_bus_driver override_map [cpu_bus_driver] ;
function cpu_bus_driver lookup(cpu_bus_driver key);
return overrride_map[key];
endfunction
function cpu_bus_driver create_object(cpu_bus_driver override_obj);
return override_obj.create_object();
endfunction
endclass