Encapsulation, inheritance, and Polymorphism in vb ., Vb Polymorphism

Source: Internet
Author: User
Tags class generator

Encapsulation, inheritance, and Polymorphism in vb ., Vb Polymorphism

The object-oriented programming mechanism is introduced in VB, which makes the language have three main features of object-oriented language encapsulation, inheritance and polymorphism, greatly improving the efficiency of application development. However, most object-oriented design languages provide polymorphism through inheritance, while vb provides polymorphism through multi-slave ActiveX interfaces.

In the previous article, I briefly described the classes, objects, and classes in vb. Next I will talk about the implementation of encapsulation, inheritance, and Polymorphism in vb.

1. Encapsulation

On the surface, it means to package and seal some things. The encapsulation in vb is roughly the same as that in vb, but what is encapsulated in vb is not a specific thing, but some methods and events. In the previous article, I mentioned how to define classes and how to generate classes in vb. One of the methods is to generate a class module directly, and the second method is to use the class generator, both methods encapsulate custom methods and events into one type. In fact, the process of generating classes and defining methods and events is encapsulation.

2. Inheritance

Inheritance in vb is implemented through two methods. The first method is to copy the source code in the parent class to the subclass, which is called the Flatten method. The second is to use objects as members. In the second method, when an object is used as a member, the object is first instantiated and initialized, and the object is released at the end of use.

3. Polymorphism

On the surface, polymorphism refers to different States of things. In vb, the specific meaning is that different objects receive the same message to produce different results. For example, in a company, the boss said: Let's get started! At this time, all employees of the company will return to their positions and do different jobs. I will use a picture to describe polymorphism.





In the implementation process of middle polymorphism, interface classes and implementation classes are defined. The meaning of interfaces is the description of the functions of things, and the Implementation class is the specific implementation of the functions of things. For example, the computer has the function of playing music, And when playing music, it is played by a speaker. Here, the computer is an interface class, and the speaker is an implementation class.

Polymorphism is an important feature of object orientation. Simply put, "one interface and multiple implementations" means multiple forms of the same thing. Programming is actually a process of abstracting the specific world. polymorphism is an embodiment of abstraction. It abstracts the commonalities of a series of specific things, and then through this abstract things, dialog with different things.

Abstract-encapsulation-inheritance-polymorphism is a four-step process in object-oriented programming. In the future, we will continue to learn them in depth and strive to let them be applied to the software we designed, it embodies our spirit of serving the people wholeheartedly.



Java encapsulation, inheritance, and Polymorphism

Encapsulation, inheritance, and polymorphism are three main features of JAVA object-oriented programming.
1. Encapsulation: encapsulates objective objects into abstract classes, and classes can only perform trusted class or object operations on their own data and methods to hide untrusted information. Encapsulation is one of the characteristics of a class. It should be well understood that, for example, some private classes, other classes are not accessible and all have access permissions, Which is safer.
2. Inheritance: it can use all the functions of an existing class and extend these functions without re-writing the original class.
Inheritance can be implemented in three ways: inheritance, interface inheritance, and visual inheritance.
3. Polymorphism: To put it simply, assign a pointer of the subclass type to the pointer of the parent class.
There are two methods to achieve polymorphism: Method overwrite and method overload.
JAVA is profound and profound. It can be explained in a few simple words. I will not talk about it here. I simply want to adopt it ~

A Java code contains three features: polymorphism, inheritance, and encapsulation.

First understand the text. You are reading the Code:
Encapsulation: The simplest example is javaBean. A student class you learned encapsulates attributes of all students, such as names and ages.
Inheritance: The methods and attributes of sub-classes that have parent classes are inherited.
Polymorphism: extends and implements are the manifestations of java polymorphism. polymorphism is a characteristic of java programs.

Differences between inheritance and interfaces:
Assume that there is an abstract class public abstract class door (){}
There is also a functional interface to describe the door:
Public interface Idoor (){
Public void baojing ();
}

Okay, if you want to inherit (extends) the description, then inheritance means that the class you implement belongs to the "door" Class of material, no matter what method you have in it, the essence of your class is "door"
If you implement the Idoor interface and implement the baojing (Alarm) method, it means that your door has the alarm function.
Inheritance focuses on describing the essence of matter,
Description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.