Trung tâm đào tạo thiết kế vi mạch Semicon


  • ĐĂNG KÝ TÀI KHOẢN ĐỂ TRUY CẬP NHIỀU TÀI LIỆU HƠN!
  • Create an account
    *
    *
    *
    *
    *
    Fields marked with an asterisk (*) are required.
semicon_lab.jpg

ENCAPSULATION

E-mail Print PDF

Many times we might use the Base Class or Base Class library provided by third party sources. By default, These Class Members are Public in nature.

It means these Class Members can be accessed directly from outside of that Class. But sometimes Base Class providers may restrict how others can access the Class members as a safety/security measure, preventing corruption of internal states and logic. To support those restrictions.

Class Members can be declared with following two Qualifiers:

  1. Local: It is available only to methods inside the class. Further, these local members are not visible within subclasses.

  2. Protected: It is a property or method has all of the characteristics of a local member, except that it can be inherited; it is visible to subclasses.

Let us understand both the above mentioned Qualifiers with examples:

Example: Local Variable Qualifier with Error Result

class parent; 

  local int a; 

endclass 

 

program main; 

  initial 

    begin 

      parent p = new(); 

      p.a = 777; 

    end 

endprogram


Example: Local variable Qualifier access using method

class parent; 

  local int a; 

  

  task set(int b); 

    a = b; 

    $display(a); 

  endtask 

endclass 

 

program main; 

  initial 

    begin 

      parent p = new(); 

      p.set(777); 

    end 

endprogram


Example: Local Variable Qualifier access in Subclass/Child Class

class parent; 

  local int a; 

endclass 

 

class child extends parent; 

  function new(); 

    a = 10; 

  endfunction 

endclass 


Example: Protected Variable Qualifier

class parent; 

  protected int a; 

endclass 

 

class child extends parent; 

  function new(); 

    a = 101; 

  endfunction 

endclass

Bạn Có Đam Mê Với Vi Mạch hay Nhúng      -     Bạn Muốn Trau Dồi Thêm Kĩ Năng

Mong Muốn Có Thêm Cơ Hội Trong Công Việc

Và Trở Thành Một Người Có Giá Trị Hơn

Bạn Chưa Biết Phương Thức Nào Nhanh Chóng Để Đạt Được Chúng

Hãy Để Chúng Tôi Hỗ Trợ Cho Bạn. SEMICON  

Last Updated ( Saturday, 29 May 2021 14:04 )  

Related Articles

Chat Zalo