I have found this to be common:
creating any agent/env configuration object, with it’s fields defined as protected, and the only way to access or override their values is through functions, for example:
protected apb_vif_t dut_vif;
protected uvm_active_passive_enum is_active = UVM_ACTIVE;
protected bit has_coverage = 1;
virtual function apb_vif_t get_dut_vif();
return dut_vif;
endfunction
virtual function void set_dut_vif(apb_vif_t dut_vif);
this.dut_vif = dut_vif;
endfunction
virtual function uvm_active_passive_enum get_is_active();
return is_active;
endfunction
virtual function void set_is_active(uvm_active_passive_enum is_active);
this.is_active = is_active;
endfunction
virtual function bit get_has_coverage();
return has_coverage;
endfunction
virtual function void set_has_coverage(bit has_coverage);
this.has_coverage = has_coverage;
endfunction
I understand protected class members, mean that they are only available to the base and any extended class down the line, and that they aren’t accessed through the dot operator from outside the class, so this method of setting all data to be protected, with individual get and set methods, is considered a safety mechanism to prevent any unauthorized accessing or overriding (no individual set or get)? can someone elaborate on why this structure stands please?
Thank you.