For understanding factory usage

Dear All,

I’m trying to understand about factory with the below code.

// Code your design here
`include "interface.sv"
`include "sequence_item.sv"
`include "sequencer.sv"
`include "sequence.sv"
`include "driver.sv"
`include "monitor.sv"
`include "agent.sv"
`include "environment.sv"
`include "test.sv"


class state extends uvm_component;
	`uvm_component_utils(state)
  function new(string name, uvm_component parent);
		super.new(name,parent);
	endfunction
endclass
		
class florida extends state;
	`uvm_component_utils(florida)
	function new(string name, uvm_component parent);
		super.new(name, parent);
	endfunction
endclass

class new_york extends state;
	`uvm_component_utils(new_york)
	function new(string name, uvm_component parent);
		super.new(name, parent);
	endfunction
endclass

module top;
  import uvm_pkg::*;
  bit aclk;
  bit areset_n;
  //test_1 t1;  
  interface_1 intf_1(aclk ,areseet_n);
  initial begin
    //t1 = new("T1",null);
    aclk = 0;
    areset_n = 1;
    run_test("test_1");
  end

  state my_state1, my_state2;
  
  initial begin
    uvm_config_db#(virtual interface_1)::set(uvm_root::get(),"uvm_test_top.env.a1","intf_1",intf_1);
  end
  always #1 aclk = ~aclk;
  
  
  initial begin

    factory.set_type_override_by_type(state::get_type(), florida::get_type());
   
   	my_state1 = state::type_id::create("my_state1", null);
    `uvm_info("INFO1",{"my_state1.type=",my_state1.get_type_name()},UVM_LOW)
	
    factory.set_type_override_by_type(state::get_type(), new_york::get_type());
   
    my_state2 = state::type_id::create("my_state2",null);
   `uvm_info("INFO2",{"my_state2.type=",my_state2.get_type_name()},UVM_LOW)
    
  end
  
  
endmodule




In especially, I want to know how to setup and use the factory concept. So I make the below code.

  initial begin

    factory.set_type_override_by_type(state::get_type(), florida::get_type());
   
    my_state1 = state::type_id::create("my_state1", null);
    'uvm_info("INFO1",{"my_state1.type=",my_state1.get_type_name()},UVM_LOW)
	
    factory.set_type_override_by_type(state::get_type(), new_york::get_type());
   
    my_state2 = state::type_id::create("my_state2",null);
   `uvm_info("INFO2",{"my_state2.type=",my_state2.get_type_name()},UVM_LOW)
    
  end

Do I understand correctly the usage of factory ? Is it implementing correctly the usage of factory?
Basically, as i know, the factory is based on override and polymorphism.


function void set_type_override_by_type (uvm_object_wrapper original_type,
                                         uvm_object_wrapper override_type,
                                         bit replace = 1)


If I understand correctly the usage of factory, then why does “set_type_override_by_type” function need the parameter of original_type and override_type ? I mean that does original_type override to override_type or override_type override to original_type ?
and What does

In reply to UVM_LOVE:

When you call

my_state1 = state::type_id::create("my_state1", null);

state is the original requested type. The create() method returns an object with the override type. Normally, the call to set_type_override_by_type() is in the top-level test, and the call to create() is in another class at a lower level.

In reply to dave_59:

In reply to UVM_LOVE:
When you call

my_state1 = state::type_id::create("my_state1", null);

state is the original requested type. The create() method returns an object with the override type. Normally, the call to set_type_override_by_type() is in the top-level test, and the call to create() is in another class at a lower level.

I’ve got one more question.
set_type_override_by_type looks like 2 kind type usage way.

function new(string name, uvm_component parent = null);
super.new(name, parent);
'uvm_info(get_type_name(), “new…”, UVM_FULL)
factory.set_type_override_by_type(cdnUvmSequencer::get_type(), cdnUvmuserSequencer::get_type());
endfunction

virtual fuction build_phase(uvm_phase phase);
set_type_override_by_type(uvm_reg_map::get_type(), uvm_reg_user_map::get_type());
super.build_phase(phase);

endfunction

As you see that there are 2 types way to use set_type_override_by_type()
one is factory.set_type_override_by_type~~, and one is just start set_type_override_by_type without a factory syntax. Would you please let me know the difference betwwen them?

In reply to UVM_LOVE:
See the definition of uvm_component::set_type_override_by_type

In reply to dave_59:

In reply to UVM_LOVE:
See the definition of uvm_component::set_type_override_by_type

Thanks, factory.set_override_by_type() looks the origial type.
then what is the set_override_by_type() without factory ? When do we use that?