Object-Oriented programming has been used in Versions later than vb4.0. Unfortunately, some object-oriented features such as inheritance, method overloading, and method coverage are not implemented.
In VB. NET, VB has become a complete OO language. Generally, the OO programming language supports four main features:
◆ Define action Abstraction
◆ Encapsulation Encapsulation
◆ Polymorphism
◆ Inheritance
Let's take a general look at the OO features of VB. NET:
Abstract:
VB supports abstraction from vb4. The first step of object-oriented is about entities. Here, the process of extracting the necessary information of an object is called data abstraction.
Encapsulation:
Encapsulation allows us to hide the complete details inside the class. Binding data and functions together is called encapsulation. This is the concept of separation between interfaces and implementations. Encapsulation is also implemented after vb4.
Polymorphism:
Polymorphism is also implemented in vb4. Polymorphism is a feature that allows us to have multiple different functions with the same name in the object-oriented system. The difference between functions is that the parameters passed to them are different. In fact, VB supports polymorphism in two ways
1. Bind
2. multi-interface execution
Inheritance:
A major improvement of the. NET platform is the ability to use inheritance. Vb5 introduces "interface inheritance" so that VB developers can expand existing objects to a certain extent. However, you can only access the interface rather than the underlying execution.
Inheritance means that a class can obtain all the interfaces and actions of an existing class. Such a class is called a subclass.
When we construct a new class that inherits the interfaces and actions of an existing class, we create a subclass of the class.
For example, in vb5 or VB6, you can create an "employee" with attributes such as name and address. If you want to create a new class like "worker", "officer", or something else, you cannot simply extend the existing employee class. As an alternative, you can choose to copy code to a new object, or use the delegate technology, we have full inheritance in VB. NET. You can inherit the employee class, including all the correct code, including validation, read, and storage. You can add individual features for each employee. If you need to change the standard behavior, you can overwrite, reload, or hide the methods and attributes of the base class.
Overwrite:
Replace the methods or attributes of the base class with the same name.
Overload:
Add new implementation methods for different parameters.
Hide:
Replace the attributes with the same name in the base class.
Inheritance also applies to virtual classes such as forms and controls. This allows VB. net to create a basic form, including terraate logos, standard menus, help systems, etc. Then inherit them and create a specific form with the same appearance and feeling as other forms.
Option strict on Imports system. Windows. Forms Public class employee Protected count as int32 'available to descendants but not public Public overridable sub funct1 () Count + = 1 MessageBox. Show ("Employee funct1:" & COUNT. tostring, "employee. funct1 ", Messageboxbuttons. OK) End sub Public overridable sub funct2 () Count + = 1 MessageBox. Show ("Employee funct2:" & COUNT. tostring, "employee. funct2 ", Messageboxbuttons. OK) End sub End Class Public class officer Inherits employee Public overrides sub funct2 () Count + = 1 MessageBox. Show ("Officer:" & COUNT. tostring, "officer. funct2 ", Messageboxbuttons. OK) End sub Public sub special () 'The function only for officer. Count + = 1 MessageBox. Show ("officer's special:" & COUNT. tostring, "Officer. Special", messageboxbuttons. OK) End sub End Class Module module1 Sub main () Dim Arun as Officer Arun = new officer () Officer. funct2 'Will call the method defined in officer Officer. funct1 'Will call the method defined in employee End sub End Module |
Prevent inheritance:
The created class can be used as the base class by default. Sometimes I want to create a class but cannot be inherited.
We can add the "notinheritable" keyword when declaring the class:
Public notinheritable class arungg ...... End Class |
When using this class, no other code can use the inherits keyword to create a subclass of our class.
Conclusion:
In VB. NET, the VB language was finally completely transformed into a thorough OO language. We now have complete inheritance and other features. VB. NET not only provides us with complete object-oriented features, but also changes some of the methods we used VB6 in the past.