quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Extending already defined methods

AOP allows us to add new code to already defined methods in 3 different ways

   

space.gif

  • before : Add code in extended method before executing any new code in orginal method
  • after : Add code in extended method after executing all the code in orginal method
  • around : Replace orginal method code with extended method code
   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example : Extend Methods
   

space.gif


  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
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation : Extend Methods
   

space.gif

 [2] Value of i 20
 [1] Value of i 10
 [1] Value of i 11
 [2] Value of j 21
 [2] Value of k 21
 [2] Value of i 30
 [1] Value of i 10
 [1] Value of i 11
 [2] Value of j 31
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com