Philosophical Origin of Object-Oriented Programming

Source: Internet
Author: User

I had imagined writing a question like "The Philosophical Origin of object-oriented programming". Just by taking a pen on the paper, I found that such a question was sufficient to produce a book and could not be written. But I still want to write my own thoughts and thoughts.

Java is used as an example. As we all know, four basic elements of object orientation are abstract, encapsulation, inheritance, and polymorphism ).

Many people insist that logic is the basis of materialism. Philosophy is the abstraction of natural disciplines. Looking at Plato, we feel that philosophy is a kind of speculation that cares about nature and mankind. logic is a tool that can be directly involved in reality, guide people's production and life. For details about the logic, you can read Yin haiguang ("Yin haiguang's philosophical and cultural thoughts ). According to my understanding, philosophy is to sum up all kinds of human experience. After a high degree of refinement and meticulous dialectics, we can write texts such as definitions and compile them into a code for viewing, this can reduce the number of people in the future.

I don't know whether Aristotle is the originator of logic or not. The Wisdom of ancient Greece is truly colorful. Let's talk nonsense. Let's take a look at some definitions. The books on hand were published by the Sanlian bookstore in 1951, co-authored by vinogldorf and Xiaoming, translated by Liu Zhizhi, full of traditional Chinese characters --

「 Our understanding of nature and society begins with the sensation of objects in the material world that act directly to the senses. It is the reflection of our consciousness on material objects or properties such as hardness and color .」

It is very important. It is the first step for us to understand things. Human beings can develop the "Sixth Sense", showing the potential of human beings to recognize the world. We feel that it is the response to the object. Objects are very important. We have summarized things through comparison among tens of millions of objects in the world and divided them into categories. For example, the outline species of biology, after a long-term understanding of natural organisms (objects), we gradually come to understand them. The layers of understanding are abstract layers, which correspond to different levels of concepts, finally, the above classification emerged. The higher the upper level, the higher the abstract level, the stronger the generalization, and the wider the concept. In the object-oriented design, it is embodied as an interface.

Species and species are classified and conceptual categories. With people's understanding of the objective world biology, the concepts of species have been abstracted to those of the door, the gate is the highest abstraction of such concepts. The "Gate" can correspond to interfaces in OOP. Classes and concepts are synonyms to some extent.

Bruce Eckel in his classic book thinking in Java: Everything is an object (everything is an object ). Everyone regards this as a "quote of Chairman Mao. In logic, we have explained this: "The things and phenomena in the real environment around us are called objects in logic )」. Now, we can roughly see the philosophical context of Object-oriented Thinking from logic. Bruce made the philosophical language literary and infectious.

The object is meaningful because it can be perceived because it "exists 」. Only when an object occupies space and time can its coordinates be established in the universe to indicate its existence. This is not much to mention. In the computer world, various software and hardware environments constitute a virtual world. OneProgramWhat is the significance of storing it on a hard disk only in the form of concepts (source code of the class? We need to let the program run and execute his work to make sense.CodePeople, it is not a white flow. Therefore, we need to make the classes (concepts) in the source code more meaningful, so that they exist and run. We often use the new keyword to target a class. The object is the initial space occupied by the class. When a method is called, "behavior" is generated, which takes up the CPU time and is very good, it occupies the memory space and CPU time, establishes its coordinates in the memory, and indicates that it exists. Since then, it has made sense.

Similarly, if an object loses its meaning in the memory, you can call the Destructor method (Note: The garbage collection mechanism in Java can automatically recycle meaningless objects ), release space and time to other meaningful objects. The same is true for humans. every living person is an object. when they die, they need to cancel their accounts and release their occupied space and time for the new generation after.
In my understanding, the concept is the abstraction of objects in the objective world. The concept is only a set of data and can be expressed by numbers, the concept expounds the views of humans on the earth on the world around them. The concept is induction, and the concept is class (the concept in OOP, class is more accurate to type ), concepts can return to the world. concepts are the first step for people to understand things logically and are the smallest "unit 」. The definition in the book is as follows:

"Concept is the reflection of the general and essential attributes of an object (the essential attribute of an object is the attribute that represents the fundamental nature of an object ).」

Aristotle first elaborated on the concept of category, such as "Birds" and "fish 」. When you see a group of birds, you will have the feeling to compare, distinguish, and finally get to know them. Very important --

「 Things are first known by comparison .」

So in Java's cosmic Class Object (object, material meaning) class, there is the equals method. All classes inherit the object class. Equals means to compare two objects in the program. By the way, I will explain the definition of comparison:

「 This is a logical method used to determine the objects and phenomena of the objective world, similar points and points of difference .」

In short, how can we get the concept? Through abstraction.

Abstract action: this is a logical method that separates objects and phenomena from their non-essential and sub-level properties .」

And the definition of the concept. In any process of thinking, it is impossible to use abstraction. When we write a program, we write an "airplane" Class (that is, the concept of "airplane", but the language of the concept is not English or Chinese, it is a program language such as C or Java. First, we need to "abstract". First of all, we need to look at the four main characteristics of object-oriented, that is, this abstraction.

When we write an airplane class, we will observe as many planes as possible (objects) because of the number and degree of observation, it has a direct relationship with the depth of understanding the concept of aircraft. It will play a major role in summarizing and abstracting the concept to the final concept. For example, if we only observe the plane's appearance and observe the internal mechanism (such as the engine), this concept may change. Our research abstracts the first step-aircraft organic wing, fuselage, landing gear, etc. As the number of observations increases and the degree of observation deepens, we further abstract the aircraft, added engine and cockpit attributes.

Concepts and words: we need to talk about the concepts. As we have defined the concept of aircraft above, aircraft is a word. Concepts are mostly nouns, And the mind will naturally do these things well. The attribute is also a noun, and the method is a verb. In a class, attributes are used to store data, and methods (or functions) are used to operate on the data. In a further step, verbs are used to modify nouns. A class name is a subject and a noun predicate. It forms a complete statement and is also a complete concept. The meaning of a method in the name of a verb is the behavior pattern expressed by a specific object during conceptual regression. If we abstract the concept of aircraft, we can use this concept to determine whether an object in the objective world is an airplane, but the objective meaning of an aircraft itself is the significance of this specific object-it can transport goods or perform combat tasks. Fold the landing gear when you fly, and open the landing gear when you land. "collapse" and "open" are behaviors and are the methods of this "airplane. A method is a verb name that represents an action. It modifies and limits its attributes. attributes are nouns and form a verb-object structure.

Back to the truth, if you are a little familiar with object-oriented programming for attributes, you will understand its meaning.

"The quality and features of an object are logically called attributes .」

In the abstract of aircraft, we listed attributes such as the wing, landing gear, and engine. There is no doubt that the quality and characteristics of the aircraft are described.

It seems that object-oriented programming thinking does have a clear philosophical source. When writing the "airplane" class, we wrote the above attributes and then encapsulated them very naturally. These modifiers include private, public, and protected, only to limit the openness of class attributes. For example, private attributes cannot be directly used in inherited classes (concepts). This encapsulated philosophy is directly related to logic. But there is a profound imitation of biology.

Inheritance imitates biological inheritance. Future generations inherit the father's genes and have some biological characteristics of the father. For example, we abstracted the plane, and the ancestor of the plane was the one of the Wright brothers. What we produced later was the constant enrichment of the concept of the Wright Brothers plane. Suppose we have written a "airplane" (concept) of the Wright brother. Later we witnessed the development of the airplane, and we will constantly write new classes, inherited from the original airplane 」. These inherited classes (concepts) have more features and qualities, so we need to add them. For example, if a jet aircraft appears, it is necessary to add a turbine engine and a stealth fighter. We need to add the coating material to this attribute, and a seaplane appears, it is necessary to inherit or add the ship's attributes-crossbreeding is also possible, such as a scorpion.

When we use a private Modifier on the attributes of the parent class (father), that is, this attribute is a recessive gene that is implicitly inherited to the next generation. The next generation cannot directly express these attributes (quality and characteristics), and of course they cannot be used. Even so, these genes (attributes) are inherited. As long as we do not implement the strict "encapsulation", the sub-class (son) will have all the features inherited from the parent class (father). What can the father do? The son can also (no genetic mutation said, after all, the CPU must be strictly controlled. Otherwise, it will become a smart computer. We are afraid there is still a way to go ).

The father has ten sons, each of which inherits the father's qualities (attributes of the class) and behaviors (methods of the class), and each has its own characteristics, for example, they all have arm and legs, and the father will use them for farming. The sons may have different kinds of endowment, or stick martial arts, or flip books and write, or engrave and polish, or cutting and completing design-there will always be new features, so we need to re-write this logic (the behavior logic) in the method. Therefore, after defining a new behavior, it is different from the father. When the father ordered the sons to: they all gave Lao Tzu the hands and feet of the activity-some of them cut their clothes and accessories, some of them danced with great guns, and some of them shook their heads. This is polymorphism, which is the State of an attribute. Because of its inheritance, the concept is enriched and different behavior states are generated. Polymorphism occurs because of inheritance. Inheritance itself is the enrichment and perfection of concepts. The new aircraft has come out and has new attributes and functions, the old aircraft type derives the new aircraft type to explain the new concept of the current aircraft. Polymorphism is the result of inheritance and an evolutionary process. Because the world cannot always be the same. The concept of ant financial, which is close to the beach, has wings and is of great significance to the survival of life.

As a result, the philosophical context of the four main elements of object-oriented can be touched. Practical Philosophy has its practical significance. as a scientific tool, it should be carefully studied. As for others, you cannot understand them. To understand them, you can be either a madman or a real philosopher. I will only summarize some of my recent thoughts, which are messy and hard to write. So far.

May 14
 

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.