Regarding component override methods?

I have a driver class with one analysis port and I connected the port with scoreboard port


class driver extends uvm_driver#(transaction);
`uvm_component_utils(driver)

uvm_analysis_port#(transaction) port;

function new(string name="",uvm_component parent);
super.new(name,parent);
port = new("port",this);
endfunction

endclass

class scoreboard extends uvm_scoreboard;
`uvm_component_utils(scoreboard)

uvm_analysis_export#(transaction) export;

function new(string name="",uvm_component parent);
super.new(name,parent);
export = new("export",this);
endfunction

endclass

class env extends uvm_env;
`uvm_component_utils(env)

driver drv
scoreboard sb;

function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
drv.port.connect(sb.export);
endfunction

endclass

now I have a new driver class and I’m overriding the driver class with new driver class so I’m getting the null pointer error in driver connect port in environment


class new_driver extends driver;
`uvm_component_utils(new_driver)

uvm_analysis_port#(transaction) port;

function new(string name="",uvm_component parent);
super.new(name,parent);
port = new("port",this);
endfunction

endclass

// modified env class
class env extends uvm_env;
`uvm_component_utils(env)

driver drv
scoreboard sb;

function void connect_phase(uvm_phase phase);
super.connect_phase(phase);
set_type_override_by_type(driver::get_type,new_driver::get_type);
drv.port.connect(sb.export);
endfunction

endclass


how over come the null pointer difference error

In reply to anil tirumalasetty:
First , dont need to reinstatiate the analysis port in new_driver as it will be inherited as part of the inheritance. Second, you should do factory override in build phase rather than connect_phase where components were already built. Factory override method needs to be called before the creation of the component so when the creat method is called for component methods it will return the override type.