Showing posts from May, 2017

System Verilog Encapsulation

Data Hiding and EncapsulationAs for above codes and their outputs data inherited from the parent were visible to the world outside. One object can access others data. Even the super command gave all the permissions to access the codes. Yes that sounds like a science fiction movie where super keyword can access J.A.R.V.I.S database but J.A.R.V.I.S has to smart enough to determine which data has to be protected and must remain only within the object who have the permission. This makes the programmers to dive into a security mechanism to hide the data from other class member. This is what we call encapsulation.
System Verilog has all its class members in default as public. It can be made private by declaring it as either local or protected. A local variable cannot be inherited by its subclass members. It’s not visible within the subclass and remains inside the parent class so accessing it outside parent class would result in an error whereas a protected keyword can be inherited but it can…

System Verilog Inheritance

System Verilog InheritanceSystem Verilog supports OOPS Inheritance which allows a user to inherit the class properties including the task, functions as well variables. System Verilog supports single inheritance as well as multiple inheritance.
Elaboration - Consider a case where we have declared a class named parentand we wantto its properties to be shared with other classes in the module or program too. Obviously re-writing the code with properties inside each child class will come first in our mind but that doesn’t sound great. It will certainly consume more script data and time too. So to cover this idea is what inheritance is all about.
Example – Your family has your Dad, Mom, son and a little daughter. So your Dad ( or your Mom ) is our Parent Class. You and your sister are the child classes inheriting from Parent Class. Since both children possess habits and behavior of parents. The habits and behavior are the methods that have been inherited from the parents (Parent Class).