Object-oriented programming simple basic overview

xiaoxiao2021-03-06  19

Object-oriented programming simple basic overview

Object-oriented programming simple basic overview

E-Badboy

This article simply introduces some of the object-oriented concepts, so that object-oriented beginners have a simple approach.

Object-Oriented Programming, OPP is a set of concepts and ideas, is a way to describe practical problems using computer programs, and a method of solving problems in an intuitive and efficient solution.

Let us first understand some of the object-oriented some proprietary nouns:

Class (Class)

Name Space (Namespace)

Encapsulation

Inheritance

Polymorphism

Abstract (Abstract)

Object-oriented

The object-oriented reason is mainly to solve 2 problems:

1. Reuse of the program code, which can increase the speed of program development by this mechanism.

2. Reduce the maintenance burden, package the program code with independent special special special special, and modify some of the program code, it will not affect the other parts of the program.

In the past, in order to increase the reuse of the program code, the programmer wrapped the repeated program code into a function. When this function is to be used, call this function in the program code to achieve the purpose of repetition. Different projects To use a function, the easiest way is to independent of these functions into a file. It can be independently made of original code files, or external dynamic connection functions library (DLL), and then these shared functions are referenced in each item to achieve the purpose of sharing. But in this stage, the purpose of reaching the shared code is hidden:

Thousands of functions included in the sharing function library are to be understood, and the output parameters are quite difficult.

The shared function library typically uses global variables, multiplying data between each function, and understanding the relationship between global variables and each function is comparable.

Shared Library may be scattered on different computers, and the version consistency of maintaining the shared function library between different computers is also quite complicated.

When you share a library version of the library, you may cause the program that uses these function libraries that cannot be run, causing maintenance difficulties.

How should we solve it? This involves the class.

class

Thousands of shared functions, such as define many functions in C # can make you draw, some functions are used to access files, some functions are used to manage files, but the problem is, who has a way to remember all the functions ? Thousands of shared functions, in order to make the function library can be easily used, these functions are divided into them. For example, a function for file operation is divided into a class, divided into DataSet for data access, so that the programmer's query and use, this is the so-called class.

So how do you manage? This involves the namespace.

Name space

After the shared function is classified, it is easier to query, but this is a problem that the same names are derived in different categories, which is the so-called naming conflict problem. For example, a class A in a software is used to calculate the decrease, and when you call other software classes, its A category is used to calculate the multiplication, in order to solve the problem of the name conflict, there is a concept of namespace. . Similar to Java's Package, place the class under the namespace. To use a certain type, modify the syntax into a "name space. Class Name". Thus, the same function name and class can be used under different namespaces.

In order to re-use the purpose of re-use code, the program is independent of the document, allowing other programmers to reference. However, there is also a potential problem using the library: global variables are difficult to maintain. For example, there are two functions sharing a variable, so declare this variable in the segment of global variables, but other functions of the shared function library, but also see this variable, but never use this variable, so You must do a good explanation for all global variables, detailed which functions are used to use this global variable. This information is very difficult to maintain, and it is also easy to cause the variable name conflict error. So how to solve the global variables? This involves the data package.

Data package

The data package is a problem that is used to solve global variables that is not easy to maintain. The significance of the data package is to put these functions followed by its functional unit, and then package each classified function, and only this classification function can call these data. "The attributes and behavior of the instance, the package after the package can only be called by the object name; the attributes after the package can only be accessed" (taken from the "computer operating system tutorial 2nd edition")

Previously, in order to make the program code easier to reuse, the original code used in the past, but most of them just replicated the program code that others already wrote, add some features, and this, this Just share program code, rather than repeating the functions that others have written.

So how can you solve the function of repeating the use of others already written? This involves inheritance.

inherit

The main purpose of inheritance is to use the functions that can be repeatedly written. Specifies some relationship between a class and another class. You can inherit a class and then you can use all functions written in it. For example, the Class A defines a method X and the Class B inherits A, which is to inherit the A class. After Class B is created, the X method of the Class A can be called. There is still a lot in inheritance, such as the parent class (a), subclass (b), but it is just the same.

Inheriting the good functionality that has been prepared in others is a good idea, but maybe you don't need all methods of the basic class. For example, in the Class A, there are Y, Z method outside the X method, but I just need to use it. To the X method, no Y, z method, or sometimes the method of the basic class is not what I want.

What should this do? This involves the polymorphism.

Polymorphism

There are a lot of explanations of polymorphology, we can roughly understand that in order to enhance the flexibility of inheritance, it is often necessary to change some of the functions that inherit, but do not change the function, this is the so-called polymorphism; then the simple point definition is "The ability to allow old code to call new code" (from Tom Archer "C # Technical insider": Another "polymorphism is allowed to set the parent object to be equal to one or more of his child objects, etc. After the technique, after assignment, the parent object can operate in different ways according to the characteristics of the child objects currently assigned to it ("Delphi4 programming technology insider") of Charlie Calverts)

Although inheriting someone else is easier to use, if it makes the program code, it is important to change the program code in the base class (Base Class), inheriting the expansion class of the basic class, can it be made upless ? If the basic class is developed, you want to modify your program. If the basic class is someone else, it is not good to say.

What should this do? This involves abstraction.

Abstraction

The generation of abstraction is to reduce the load of the program after reducing the program version update. The user of the function, and the user can be separated, each independent, not affected from each other. interface

In order to achieve abstract purposes, it is necessary to provide a common specification between functional providers and function users, and the functional provider and function user must be provided according to this specification and use these features. This shared specification is the interface. The interface defines the number of functions, function names, function parameters, parameter sequence, and the like. It is a programming structure that can declare attributes, indexers, events, and methods. It does not implement these members and only provides definitions. The interface defines guidelines between functional providers and function users, so as long as the interface is constant, the functional provider can change the implementation program code without affecting the people used, essentially in essential changes. Many people confuse the inheritance and interface. In fact, an example is that it should be understood that the inheritance is like a call to the internal development of it. As the previous A class B method, and the interface is like two. The common specifications made by the above system, as we call the Windows API.

The benevolent seeing the wisdom of the benevolence, the knowledge of the author's knowledge is limited, and it is welcome to correct it.

Note: Please indicate the source. E-Badboy

Www.hackk.net

2003-1-5

Reference book:

Grant Palmer's "C # programmer reference manual"

Tom Archer's "C # Technical Insider"

Charlie Calverts's "Delphi4 programming technology insider"

Youth Publishing House "C # Technology Platform Practice Drive"

Tsinghua University "Computing a few operating system tutorial 2nd edition"

转载请注明原文地址:https://www.9cbs.com/read-48841.html

New Post(0)