当前位置:网站首页>SystemVerilog learning-07-class inheritance and package use
SystemVerilog learning-07-class inheritance and package use
2022-07-01 06:14:00 【Vuko-wxh】
Class inheritance
What is inheritance ?
Inheritance is a key concept of the object-oriented programming paradigm . Class is used to create user-defined types . Inheritance makes it very safe for users to use , Add or modify the behavior of the class in a non intrusive way . The process of extending a base class and generating new subclasses is called class derivation , When a class is extended and created , The derived class inherits the data members of its base class 、 Properties and methods , This is class inheritance .
The inherited class can realize the following functions :
Inherited the methods of the original class , And can be modified
Add new methods
Add a new data member
While realizing the above functions, certain rules must be met :
Subclasses inherit all data members and methods of the parent class
Subclasses can add new data members and methods
Subclasses can override data members and methods in the base class
If a method is overridden , It must maintain parameters consistent with the original definition of the base class
Subclasses can be passed through super Operator to reference methods and members in the parent class
Be declared local Data members and methods of can only be visible to themselves , Not visible to both external and subclasses ; Yes, the statement is protected Data members and methods of , Invisible to the outside , Visible to itself and subclasses .
Inheritance and subclasses
Previously defined classes Packet, You can enter — Step extension to form a new class LinkedPacket. adopt extends,LinkedPacket Inherit from its parent class Packet, Including inheriting all its members ( Variable / Method ).
class LinkedPacket extends Packet;
LinkedPacket next;
function LinkedPacket get_next();
get_next = next;
endfunction
endclass
Subclasses can inherit members of the parent class , therefore LinkedPacket The object is also a legal Packet object .
thus , The parent class handle can point to the object of the child class .
LinkedPacket lp = new;
Packet p = lp;
Handles to parent and child classes , The subclass handle can be directly assigned to the parent handle , Subclasses can have member methods with the same name as the parent class , A child class can have a member variable with the same name as the parent class .
super
super Is the member used to access the current object and its parent class . Especially if the member of the subclass has the same name as the member of the parent class , Then you need to use super Specify its parent class members to access , Instead of the default subclass member .
class Packet; // base class
integer value;
function integer delay();
delay = value * value;
endfunction
endclass
class LinkedPacket extends Packet; //derived class
integer value ;
function integer delay();
delay = super.delay ()+ value * super.value;
endfunction
endclass
Use of the bag
The definition of package
In order to make it possible to work in multiple modules ( Hardware ) Or class ( Software ) Share user-defined types between ,SV Added package (package) .
The concept of package refers to VHDL, User defined types such as class 、 Method 、 Variable 、 Structure 、 Enumeration classes can be found in package…endpackage In the definition of .
Export the contents of the package
module、interface、class You can use the content defined or declared in the package .
You can use the index of the field :: Number directly refers to .
definitions::parameter definitions::instruction_t inst
You can specify to index some types defined in the package to the specified domain .
module M; import definitions::instruction_t; instruction_t inst; endmodule
Through wildcards * To import all categories in the package into the specified domain .
module M; import definitions::*; instruction_t inst; endmodule
Distinction between packages and libraries
package This container can be used to isolate types .package The significance of is to make the software ( class 、 type 、 Such method ) Encapsulated in different domains , To isolate from the global domain .
Libraries are compiled products , Hardware ( module、interface、program) Will be compiled into the library , If you don't specify a compiler , Will be compiled into the default library . The library can accommodate hardware types , It can also accommodate software types , For example, class 、 Methods and packages .
Packages can only contain software types, such as classes 、 Methods and parameters .
reference
- Verification of West circuit department PPT
边栏推荐
猜你喜欢
随机推荐
SystemVerilog学习-08-随机约束和线程控制
skywalking集成nacos动态配置
Save data in browser to local file
JDBC connection pool
连续四年入选Gartner魔力象限,ManageEngine卓豪是如何做到的?
restframework-simpleJWT重写认证机制
SystemVerilog学习-06-类的封装
利用百度地图查询全国地铁线路
交换机配置软件具有的作用
highmap gejson数据格式转换脚本
【ManageEngine卓豪】移动终端管理解决方案,助力中州航空产业数字化转型
OpenGL es: (1) origin of OpenGL es (transfer)
Multi label lsml for essay learning records
Top 10 Free 3D modeling software for beginners in 2022
DHT11 温湿度传感器
HDU - 1501 Zipper(记忆化深搜)
Solve the problem of garbled files uploaded by Kirin v10
Minio error correction code, construction and startup of distributed Minio cluster
El tooltip in the table realizes line breaking display
相同区域 多源栅格数据 各个像元行列号一致,即行数列数相同,像元大小相同