Getting class derivatives names from factory

In reply to nimrodw:

One possible solution ::

(1) Within class example_a_b_class_base add property ::

 static  string  base_h_q[$] ;  

(2) Then within all extended class definition add the following macro ::

  `LOGIC  
 Macro  `LOGIC  is  defined  as  ::

       `define LOGIC  local static  string  tname = store_type_name() ; \
   local static  function  string  store_type_name() ;  \
        if( type_name != "example_a_b_class_base" )  begin \
          base_h_q.push_back( type_name ) ; \
        end  \
        return type_name ; \
   endfunction
     

NOTE :: User must ensure that macro `LOGIC is used in any extended class definition added in future

(3) Within function get_random_a_b_class_type ::


    virtual function string get_random_a_b_class_type();
        uvm_factory fact = uvm_factory::get();
        example_a_b_class_base  base_h ;
      
 // Magic that makes a_b_class_names_q = {"a_bigger_than_b", "a_smaller_than_b", "a_b_equal"};
        a_b_class_names_q = example_a_b_class_base :: base_h_q ;
        a_b_class_names_q.shuffle();
         
         $cast( base_h , fact.create_object_by_name( a_b_class_names_q[0] , "", { a_b_class_names_q[0] , "_h" } ) ); 
         
     //  3rd  Argument  to  create_object_by_name  is  string  name  of  created  objected  
          
         //  Below  Statements  for  Debugging  :: 
        `uvm_info(get_type_name() , $sformatf(" Created  type_name  as  %0s ", base_h.get_type_name()  ) , UVM_NONE )

         if( base_h.randomize() )
             $display("Success  with a == %0d , b == %0d ", base_h.a , base_h.b );
        
    endfunction : get_random_a_b_class_type

       

I am certain there would be a cleaner way to achieve the same .