VB. NET Object-Oriented Design

Source: Internet
Author: User
Document directory
  • 2) attributes
  • 4) Events
  • 1) Description
  • 2) Implementation of Polymorphism
  • 1) Description:
  • 2) Implementation of Inheritance
  • 3) Restrictions

Object-Oriented Programming (OOP) is a programming method for Object Modeling. An object is a real-world entity and is implemented as a package. The program package contains attributes, events, and methods of objects. Traditional programming methods focus on how different objects work together. In object-oriented systems, the focus is on Object Modeling (defining attributes, events, and methods ).

1. Object 1. Description

1. Define an object. The system will automatically allocate a certain amount of memory space for it to store information about the object.

2. During object usage, the object will always occupy the memory space.

3. After the object is used up, the memory space occupied by the object will be released. (Otherwise, the system's limited resources will be wasted)

2. Create

Dim object name as new namespace. Class Name

Or:

Dim object name as namespace. Class Name

Object Name = new namespace. Class Name

Instance: dim lblud as system. Windows. Forms. Label


Lblud = new system. Windows. Forms. Label

3. Set attributes

1. Set attributes: Object Name. attribute name = Attribute Value

2. Read attributes: variable name = Object Name. attribute name

3. Object used: Object Name. Method Name (parameter list)

Note: The parameter list is not required. If a parameter is required, add the parameter to the parentheses. Multiple parameters are separated by commas.

Ii. Category 1. Declaration

Access permission modifier Class Name

.........
// The topic of the class. The class member is defined here.

End Class

2. Define member 1) variables

Access permission modifier variable name as Data Type

Instance: public name as string

2) attributes

Note: There are three types of attribute delimiters:

1. access permission limiters: public, protected, and shared

2. read/write limiters: readonly (read-only), writeonly (write only), and readable and writable by default.

3. Redefinition restriction: notoverridable (this attribute cannot be re-written in a derived class) and overridable (this attribute can be overwritten by the same name attribute in a derived class)

3) Method

1. member function: function Process


Description: A member function is a function declared inside a class. A member function can return function values.

2. Member process: Sub Process


Note: The member process refers to the sub process declared inside the class. The member process has no return value.

4) event 3. Object-oriented features 1. Encapsulation

The definition class includes attributes, events, and methods. A class instance is self-contained. Other external modules cannot add new attributes, events, and methods to an object. This feature of an object becomes encapsulation.

Once the related attributes, events, and methods of the class are defined, other project modules can use the object instances of the class without worrying about how the class processes data, that is, data hiding.

2. polymorphism 1) Description

Different objects receive the same message, which produces different behaviors. The same class shows different behavior characteristics in different situations.

2) Implementation of Polymorphism

1. Overwrite: it refers to the method for the subclass to redefine the virtual function of the parent class.

Note: When the methods defined in the parent class are modified with the keyword overridable, The subclass uses the keyword overrides to define the methods with the same name in the parent class, so that the methods defined in the subclass will overwrite the methods with the same name in the parent class.

2. Overload: multiple functions with the same name are allowed, and the parameter tables of these functions are different.

3. Inheritance

1) Description:

1. The subclass is derived from the parent class and can be used as the parent class of the next level subclass. In this way, a multi-level subclass derived from a top-level parent class forms a class hierarchy.

2. Subclass inherits attributes, methods, and events from the parent class. At the same time, sub-classes are allowed to have features that are not present in the parent class.

3. In VB. NET, subclasses can only inherit from one parent class, that is, a single inheritance. One subclass can only have one parent class, but one parent class can have multiple child classes.

2) Implementation of Inheritance

1. Implement inheritance: it refers to the ability to use the attributes and methods of the base class without additional encoding.

2. interface inheritance: only the names of attributes and methods are used, but subclasses must provide implementation capabilities.

3. Visual inheritance: it refers to the ability of the subclass form (class) to use the appearance of the base form (class) and implement code.

3) Restrictions

1. When defining a class, add the notinheritable modifier to indicate that the class cannot generate subclass.

2. When defining a class, add the mustinherit modifier to indicate that the class can only be used as the base class and cannot create an instantiated object, which is called an "abstract class ".

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.