My object-oriented program View

Source: Internet
Author: User

When searching for "Object-based" and "object-oriented", I found this article, and I felt quite well written, but I don't know where it came from.

I. misunderstandings about the object-oriented concept

"Targeting the elephant" is a bad word nowadays, just as people liked to mark their company as ". com" last year. In fact, it is hard to say how many people can really understand this word. I like this to compare people's misuse of the word "object. "Object" is like what people often say about "cool" and "Shuang". Many people do not carefully consider the differences between the two words. In many cases, they are common, "cool" and "cool" usually mean "good mood". When you are happy, you can shout "Cool, cool ", at this time, the two words are common. But you can say "This person is cool", but you cannot say "This person is cool ". People abuse the word "object" Here. "object-oriented" and "Object-based" are like "cool" and "Shuang", which are two different concepts, however, people usually confuse these two words and use "Object-Oriented" to express them. Common Errors can be listed here:
1) Someone said happily to you, "I don't like the scripting language of Flash 4. The Action Script of Flash 5 adopts the new object-oriented language ". "syntax, very comfortable to write. I have been using Flash 5 for things. "(The same discourse also occurs in director's lingo scripting language)
2) Visual Basic uses object-oriented attributes and methods, which are greatly improved compared with the basic language in the past.
3) JavaScript is object-oriented.
And so on.
When you hear something similar, you must carefully examine the speaker and analyze what he says. To be certain, he does not really know what object-oriented thinking is. Many people do not distinguish between "Object-Oriented" and "Object-based. The three characteristics of object-oriented (encapsulation, inheritance, and polymorphism) are indispensable. objects are usually used based on objects, but existing Object Templates cannot be used to generate new object types, then, a new object is generated, that is, "the object is not inherited", and "polymorphism" is a subclass object instance of the parent class, without the concept of inheritance, we cannot talk about "polymorphism ". Nowadays, many popular technologies are based on objects. They use encapsulated objects, call object methods, and set object attributes. However, they cannot allow programmers to derive new object types. They can only use methods and attributes of existing objects. So when you determine whether a new technology is object-oriented, you can usually use the last two features to determine. Both "Object-Oriented" and "Object-based" implement the concept of "encapsulation", but object-oriented implements "inheritance and polymorphism", while "Object-based" does not, indeed, it is very good.
2. java is more thorough than C ++ in implementing object-oriented ideas.
My teacher from my recent class said to me: "C ++ is a process programming activity under the guise of object-oriented." I agree with this sentence very much, and I always think so. But after listening to his explanation, I found that I only understood the meaning of the first two layers. However, I do not understand it. You may ask, "Isn't C ++ object-oriented? ". In fact, C ++ is a real object-oriented programming language. But it is also a process programming language. Why? C ++ not only considers the object-oriented feature, but also considers backward compatibility with the C language, this makes the C ++ language show the dual nature of "process" and "object" programming. You can use the C ++ compiler to write traditional C Programs, C ++ class libraries, or compile your own classes for object-oriented programming. This "Two Sides" allows people to continue to retain the original C code, but also hinders the promotion of object-oriented ideas.
For example, in 94 years, I started to learn C ++. At that time, I learned a class library called turbo vision that I brought by turbo C ++ to do the project. My classmates also use turbo C ++, but he has never learned the C ++ language at all, he just used the turbo c ++ compiler to re-compile the program he previously wrote with turbo c. Then he proudly said to me: "Look, what I made with c ++ "seems to mean" I used c ++ to develop projects ". In those years when c was more advanced than pascal and pascal was more advanced than foxbase, the C ++ label is definitely a "cool" sign. I know his behavior very well. This is the first meaning of "C ++ is a process programming activity under the guise of object-oriented, that is, the C ++ compiler creates the underlying "process activity" for the compatibility of C Programs ". For a long time in China, people are using C ++ compilers for C programming. I was thinking that, compared with my classmates, I was really an object-oriented person. I have learned the C ++ language, and I understand encapsulation, inheritance, and polymorphism. I have learned the class library of turbo vision. I have derived the class library of turbo vision and compiled my own class, so I understand object-oriented. In a sense, I think so. However, from the perspective of object-oriented programmers, I do not fully understand the idea of object-oriented. People engaged in object-oriented programming can be divided into class library creators and class library users according to their division of labor. Generally, the talents who create class libraries are people who really understand object-oriented ideas, they create class libraries for the "customer programmers" to use. They create class libraries from the beginning, and they perform the entire process of object-oriented analysis, design, and implementation. After learning C ++, my first feeling is that it is really troublesome to create a class library from scratch. It is usually easy to implement functions through C process programming, you must follow the class idea to create a new object, but once the class library is created, it is very comfortable to use the class library, the derived class, and maintain the code. Not all people who use the class library have the idea of object-oriented. They usually know how to inherit and derive new objects to use the class library. However, our thinking has not really been transferred, class Libraries are only object-oriented in form, but essentially an extension of library functions. This is what I understand: "C ++ is the second meaning of" playing the process programming in the guise of Object-Oriented ". In fact, people who use C ++ Programming, most of them do not create their own classes, but use class libraries. As a result, they take class libraries as an advanced library function library and do not really understand the idea of object-oriented.
The idea of object-oriented C ++ is very slow. People gradually accept some object-oriented ideas after libraries such as MFC, Owl, and VCL come out. Why is this object-oriented path so difficult? My answer is "C ++ gives us a second way to go through process programming". Of course, the reason is to consider compatibility with the C language, however, it is because of the second old path that we will not consider the new object-oriented programming approach.
It was not until the emergence of Java that we had ushered in the dawn of object-oriented. Is Java a revolutionary thing? No. All existing java ideas are inherited from other languages and technologies. There is no revolution. The concept of virtual machines was adopted in UCSD pascal 20 years ago, however, at that time, the machine speed was too slow, and the performance reduction caused by virtual machine simulation was quite serious for the hardware at that time. Many of java's own things also use the C ++ language, and even its founder said, java is "C ++ --" That is to say, java does not remove some bad places in C ++. Therefore, Java is essentially nothing revolutionary, so those praises of Java are all propaganda tricks of Sun. No language will survive for a long time. It is hard to say that your child will continue to use C ++ or java in the next two decades. Therefore, we should leave behind these flashy words, find what we really need to learn. Otherwise, today we will all be a zombie of Microsoft, and Tomorrow Sun will become a zombie of Sun. After carefully studying the history of the development of computer technology in the United States, Americans have always liked to sell their outdated technologies like the third world, and they can always proudly say that we will always be ahead of your third world country for 20 years. We are always learning their things behind Americans, which is indeed worrying. I spoke and ran away from my questions. Although Java has nothing to do with revolutionary things, Java is indispensable in promoting the idea of object-oriented programming. When using Java programming, you do not need to consider the backward compatible language. It is a re-established language. Before you master this language, you must switch your programming ideas from process programming to object-oriented programming. Because every Java program is a class, you can write any java program, you are not consciously constructing an object template. There is no second path, and you can only target object programming. (I like java very much to put all class definitions and class declarations in one file, rather than separating cpp and. h files like C ++. People who have just begun learning java are not used to it, but after learning for a while, you will understand its advantages .), When you use java to write a program (I prefer to write a class, rather than a program), you must consider the problem from the perspective of an object, because your program is a class, you must consider what changes are made to members, methods, classes, member variables, static variables, and methods. Usually after a project is completed, you have applied the object-oriented thinking to it. The reason why Java is more thorough than C ++ in implementing object-oriented is that you can only write java programs using object-oriented methods, C ++ can use another non-object-oriented method to write programs. Java has nothing really revolutionary. Its biggest contribution is, of course, to promote the idea of object-oriented.
Java in general reduces the possibility of continuing process programming, but does not completely eliminate it. Targeting is like an idea. It is the way we consider things. It usually shows that we solve the problem in a process, or abstract the problem into an object to solve it. In many cases, we will solve the problem through the process without knowing it, because we are usually used to considering the solution to the problem, rather than abstracting the problem into an object to solve it. Many new technologies make us more inclined to process rather than object ideas. The most obvious is the emergence of RAD (Rapid Application Development) visual technology. People can quickly develop applications by setting properties and writing event functions, writing event functions is a typical process-based programming idea (at least I think so). How many people can distinguish between VB and Delphi, C ++ builder, what are the essential differences between Java's event function writing? The last three use the delegation (delegated model). in Java, the anonymous class (untitled class) is used ), or the adapter class to implement delegation. This is a kind of object-oriented idea, But VB is not. Therefore, the underlying differences are all erased by the similarity of the upper layer. When JBuilder is used for programming, if we haven't carefully studied Java's AWT. event programming is usually used as an ordinary "VB-like" Programming Method to write a program, and the code generated in the background is analyzed, you can understand that the code is really object-oriented, But if you simply treat it Visual programming tools, you will never understand what is a "delegated model", what is object-oriented programming. This is what I understand: "C ++ is the third important thing in the process of programming in the form of object-oriented code. Both C ++ and Java may follow the old path of process programming. Java reduces the possibility of Process Writing. However, if you do not have an object-oriented programming idea, you may still follow the process-oriented path.

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.