The central idea of OOP is that programs are organized as a collection of interacting objects, each with its own data space and functions. Objects can be made reusable because they encapsulate everything they need to operate, can be built with minimal or no external dependencies, and can be highly parameterized.
Classes and Objects
Class- refers to a class declaration or an uninstantiated object
Object- object refers to an instance of a class.
class register;
local bit[31:0] contents;
function void write(bit[31:0] d)
contents = d;
endfunction
function bit[31:0] read();
return contents;
endfunction
endclass
This very simple class has one member, contents, and two methods, read() and write(). To use this class, you create objects by instantiating the class and then call the object’s methods, as shown below
module top; register r;
bit[31:0] d;
initial begin
r = new();
r.write(32’h00ff72a8);
d = r.read();
end
endmodule