|
|
1 program extend_methods;
2 // Define the class
3 class aop;
4 integer i;
5 integer j;
6 integer k;
7 function void print_i ();
8 $display ("[1] Value of i %0d",i);
9 endfunction
10 function void print_j ();
11 $display ("[1] Value of i %0d",j);
12 endfunction
13 function void print_k ();
14 $display ("[1] Value of i %0d",k);
15 endfunction
16
17 function void print_i_j ();
18 $display ("[1] Value of i %0d",i);
19 $display ("[1] Value of i %0d",j);
20 endfunction
21 endclass
22 // Add new variable j and method print2 to aop class
23 extends aop_extend (aop);
24 before function void print_i ();
25 $display ("[2] Value of i %0d",i + 10);
26 endfunction
27 after function void print_j ();
28 $display ("[2] Value of j %0d",j + 10);
29 endfunction
30 around function void print_k ();
31 $display ("[2] Value of k %0d",k + 10);
32 endfunction
33 before function void print_i_j ();
34 $display ("[2] Value of i %0d",i + 20);
35 endfunction
36 after function void print_i_j ();
37 $display ("[2] Value of j %0d",j + 20);
38 endfunction
39
40 endextends
41 // Create instance of the aop class
42 aop a_;
43
44 initial begin
45 a_ = new ();
46 a_.i = 10;
47 a_.j = 11;
48 a_.k = 11;
49 a_.print_i();
50 a_.print_j();
51 a_.print_k();
52 a_.print_i_j();
53 end
54
55 endprogram
You could download file extend_methods.sv here
|