ZZ is object-oriented, my thoughts (upper)

xiaoxiao2021-03-06  21

Foreword: The purpose of organizing this information is to help

My classmate can more intuitively understand the object-oriented programming. Let the later people can take less detours, but there is no many vulnerabilities and mistakes, but also ask the seniors to make valuable changes, after all, exchange will make us constantly progress.

The technology is a sun-changing, he will not wait for your growth. Technologies should take out to exchange in others, they learn to understand their own subjective consciousness, there is a wrong mistake! Communication will make progress faster. I think if the computer's architecture does not have a revolutionary change, the program language we applied now is not too depreciated! What is the programming? thought! Excerpt in a programming language (

It is best to go to object-oriented language), then go to other programming languages, you will find that the process is such a row of clouds! why? You have already mastered the idea of ​​programming, then learn other, nothing more than learning a new syntax format.

I am not here to discuss how to use C or Java, nor and how to learn how you discussed them, I want to discuss with you how to understand the object-oriented. It will mainly involve "class, object, inheritance, attribute, method, static, overload, hidden, refactoring, statement, definition, initialization, assignment, etc." I will only pass by, let you have one What is the meaning of this tour means that I have achieved the purpose, and more detailed technology inside, please refer to other related books and go deep into the study! Because I just discuss how to better understand the object!

How to improve efficiency? Repeat the resources and use others to use. This is a very good idea! For you, the biggest resource is confidence and enthusiasm! Ok, let's make a spirit, let us go to the object-oriented programming!

Note: All programs in the article I use Java, of course, in C , it is very small, and I will point out in different places!

Note: The text of the text in the article uses black, indicating the text with bold blue, emphasizing the text with bold orange, and the text is bold!

text:

1. basic concepts:

1.1 Preliminary prices for classes and objects:

I want to say that whether it is a process-oriented language, it is also an object-oriented language, I should first give him a class and object! -------- "What is the composition of this world?" This question will give different answers if the different people will answer. If it is a chemist, he may tell you "Is it still useful? This world is a chemical substance of molecules, atoms, ions, and the like." If is a painter? He may tell you, "This world is composed of different colors." ... huh, huh, everyone is rumored! But if you let a classified person to consider the problem, it is more interesting, he will tell you that "this world is made by different types and things" good! " As an object-oriented programmer, we have to stand at the perspective of a classified perspective! Yes, this world is made of animals, plants, etc. Animals are divided into single cell animals, multi-cell animals, mammals, etc., mammals are divided into people, elephants, tigers ... I will go down!

Now, stand in an abstract angle, we give ""

Class "Next definition! I mean, standing in an abstract angle, you answer me" What is human? "First let's take a look at some of the features of human beings, including properties (

Some parameters, values), and methods (

Some behaviors, what can he do! ). Everyone has some attributes such as height, weight, age, blood type, etc. People will work, people will walk upright, people will use their own mind to create tools! People can distinguish other types of animals because everyone has the properties and methods of the population. "Human" is just an abstract concept, it is just a concept, it is an entity that does not exist! But all "

Human "The properties and methods of this group are called people! This object"

"People" is the actual entity! Everyone is an object of this group. Why is the tiger not? Because it does not have the property and method of this group, the tiger will not walk upright, will not use tools, etc.! So Say the tiger is not a person!

This is visible -------

The class is to describe a set of objects with the same characteristic (attribute) and the same behavior (method). In the program, the class is actually the data type! For example: integer, decimal, etc. Integral also has a set of features and behaviors. The difference between the language-oriented language and the surface object is that the process-oriented language does not allow programmers to define data types themselves, and can only use the built-in data types in the program! In order to simulate the real world, in order to better solve the problem, we often need to create the data type necessary to solve the problem! Object-oriented programming provides us with solutions.

1.2 Built-in data type and function:

Computer programs must be tracked with 3 basic properties when storing data:

1. Where is information stored?

2. What is the value stored?

3. What type is stored;

Let's take a look at what is the built-in data type of the programming language! (

Oh, this is not good, because each language has its own unique data type, but this is a few, such as there is a Byte type data in Java, and there is no in C , I hope you can give an Anti-three! ), Such as integer "int", floating point type data "float"! String "string", and arrays also have structures, and so on. However, when writing the program, we will create a type of variable or constant as needed, for example, because we need to create a shaped variable i is 5, we can do this, int i = 5; and I am very It may change the value of i, which is to assign a value from the new to it, such as letting it wait and 6, you can change it in the required place to change to i = 6; thereby, we know that the amount of change can occur on "value" variable. The amount that does not change will be called constant, with count keywords in C , and in Java, use Final keywords to declare. Due to different languages ​​in different languages, don't be introduced here, detailed content clearing through books!

Here we mainly discuss functions, we can imagine functions into one "

Implement a specific function of black box "------ this feature is set by you, give an example: Now I ask you" 2 3 equal to how much? "I believe you can very fast Answer me equal to 5. Let's analyze what information is included in this sentence! First of all, I want to imagine your brain into a black box, I don't know how it doesn't know how your brain works.

That is, what is the operation), I just care about it.

What information I passed to you? What processing do you have to do? What information is you returning to me? Need to remind you that every method will return a message to the caller, except for the constructor (later I will make a detailed introduction). I need to take myself as a programmer now, and you? Of course it is a computer! Calculation can be so smart, it will only be run according to a well-known specific format, I want it to have the functions as described above, I will define this black box! First of all, I want to tell this black box will have two integer values ​​to you (

This is the so-called parameter, which is the information that the programmer needs to give the black box), then define the two integers to implement the two integers inside the black box (

This is the machining made by the black box to data, as needed, you can do any processing. ). Finally, it will be labeled it back to me, the same value is the same (

This is the information that the black box is returned to the programmer). A function is so defined, let's take a look at the writing format: