Disabling a sub-component at run time

Is their any way to not create a sub-component of a component. My exact issue is that i want to disable a monitor when a run a particular test. I don’t want to remove the monitor altogether, i just don’t want it to do nothing when i run that test case. Any pointers?

The easiest thing to do is to use the factory and override the monitor with a extension of the monitor that does nothing. i.e. just override the run method and do not call super.run.

Another alternative is to test a variable before constructing the monitor in the build phase:

function void build();

// Only build the monitor if the config class member has_monitor is true
if(config.has_monitor == 1) begin
my_monitor = my_monitor_type::type_id::create(“my_monitor”, this);
end

endfunction: build