|
Encapsulation in system verilog
|
Encapsulation in system verilog :
In system verilog all the properties of the class are public by default or we can say it be accessed outside the class directly using the dot operator. If we want to protect the access of the class variables/properties from outside the class we can use the local keyword. Hiding the properties from being accessed outside the class is called encapsulation.
If we want to make the properties accessible in the extended classes but not outside the classes. We can declare the properties as protected. Then it will be available in the extended classes but not in the main program.
class base;
local logic b1;
protected logic c1;
function new(input logic pone);
b1 = pone;
endfunction
endclass
class sub1 extends base;
integer length;
function new(input logic pone);
super.new(pone);
endfunction
endclass
class sub2 extends sub1;
...
function new(input logic pone);
super.new(pone);
endfunction
endclass
|
|
This Articles is written/submitted by puneet (Puneet Aggarwal). You can also contribute to Asicguru.com. Click here to start
|
Prev << Inheritance
|
Next >> this and super
|