Interface class polymorphism

Hi SystemVerilog forum.
I am trying to use polymorphism to make the code easier.
The following code works but I don’t want to use it


interface class inter;
   pure virtual function void print();
endclass: inter

class private_name implements inter;
   virtual function void print;
      $display("Shimon");
   endfunction: print
endclass: private_name

class last_name implements inter;
   virtual function void print;
      $display("Cohen");
   endfunction: print
endclass: last_name

class name;
   private_name pname;
   last_name lname;
      function void print_person();
         pname = new();
	 lname = new();
	 pname.print();
	 lname.print();
     endfunction: print_person
endclass

module top;
   name m_name = new();
   initial begin
      m_name.print_person();
   end
endmodule

In the following code I placed private_name and last name in an array of type inter.
Obviously it won’t work because inter cant be instantiated. how can I $cast this structure?
I need this structure because In my project I going to add many classes that implements inter, and all I want to do is to
add the name of the new class in the array.


class name;
   inter m_inter[]={private_name, last_name};
   function void print_person();
      foreach(m_inter[i]) begin
         m_inter[i] = new();
         m_inter[i].print();
      end
   endfunction: print_person
endclass

In reply to shimonc:

A simple solution is delegating construction to a static method

class wrapper #(type T);
   static function inter create;
      T obj = new;
      return obj;
   endfunction 
endclass
   
class name;
   inter m_inter[]= {wrapper#(private_name)::create, wrapper#(last_name)::create};
   function void print_person();
      foreach (m_inter[i])
         m_inter[i].print();
   endfunction: print_person
endclass

There are other ways of doing this involving factory proxy classes depending on what you are ultimately thinking about. See the links here.

Great solution thanks.
I need to model to analog behavior of IP phone, network camera, access point etc.
many classes are involved in this models.
I investigate the “Design Patterns: Elements of Reusable Object-Oriented Software” topic in order to build the model correctly.
If you have suggestions or papers on how to correctly build these kind of models it will help allot.

small anecdote about the links
I am the one that found the typo in “OOP Design Pattern Examples” :-)