JAVA basics: My personal object-oriented program View

Source: Internet
Author: User
JAVA basics: My personal object-oriented program view-Linux general technology-Linux programming and kernel information. The following is a detailed description. 1) some misunderstandings about the object-oriented concept

"Object-Oriented" 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 the misuse of the word "object. "Object" is like "cool" and "cool" that people often say. Many people do not carefully consider the differences between these two words. In many cases, they are generic, "cool" and "cool" usually mean "good mood". You can shout "Cool, cool" when you are happy ", 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 "cool", 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) I am very happy to say 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 to say, "Object-based" does not have the inheritance feature, 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 in 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, I used c ++ to do things. It seems that 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 by 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 whole 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" doing 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 "Because 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 it really 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, but it can only be object-oriented 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 which variables are used as member variables, which are used as methods, several classes to be generated, which variables are member variables, and which are 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. Object-oriented is an idea. It is a method for us to 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 an object-oriented concept, but vb is not. Therefore, the underlying differences are erased by the similarity of the upper layer. When using jbuilder 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, only then can you understand that the code is really object-oriented, But if you simply treat it as a 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-party concept of" process programming. 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.
Related Article

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.