| Login | | Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name. | |
| Who's Online | There are currently, 71 guest(s) and 0 member(s) that are online.
You are Anonymous user. You can register for free by clicking here | |
 | |
|
Verification Guild: Forums |
|
| View previous topic :: View next topic |
| Author |
Message |
spartanthewarrior Senior


Joined: Aug 15, 2009 Posts: 32
|
Posted: Sun Mar 11, 2012 7:04 am Post subject: Question: Virtual Interface Defined In Constructor |
|
|
Hi All,
I have (Class A)
class a;
function new(virtual mem_interface.MEM mem_intf_new,
virtual input_interface.IP input_intf_new,
virtual output_interface.OP output_intf_new[4] );
this.mem_intf = mem_intf_new;
this.input_intf = input_intf_new;
this.output_intf = output_intf_new;
endfunction
endclass //-- End Of Class A
class b extend a;
function new();
super.new();
endfunction
endclass
Question: How to pass arguments in (super.new) function when we have virtual interface |
|
| Back to top |
|
 |
Logger Senior


Joined: Jun 15, 2004 Posts: 340 Location: MN
|
Posted: Mon Mar 12, 2012 12:10 am Post subject: |
|
|
If you are simply looking to pass values through, you'd do this.
| Code: |
class b extend a;
function new(virtual mem_interface.MEM mem_intf_new,
virtual input_interface.IP input_intf_new,
virtual output_interface.OP output_intf_new[4] );
super.new( mem_intf_new, input_intf_new, output_intf_new );
endfunction
endclass
|
But don't get carried away with putting parameters in your constructors. I'd recommend not putting parameters in constructors unless you know what you're doing. It makes it extremely painful to refactor your code to use a factory pattern later on. UVM uses a factory pattern to good effect. If you don't use UVM, you can make your own factory, but constructor parameters become problematic.
If you're just learning the language with throw away code, this isn't a big deal. On the other hand, if you're writing code that is going to have a long life span, you'll thank yourself later. Now, how to accomplish the above without passing it in via the constructor, well that's a whole 'nother question.
-Ryan |
|
| Back to top |
|
 |
spartanthewarrior Senior


Joined: Aug 15, 2009 Posts: 32
|
Posted: Tue Mar 13, 2012 4:15 am Post subject: |
|
|
thanks much !!
it worked. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
| |
|
|