OO Wisdom in life--the five principles of object-oriented

Source: Internet
Author: User

All things in the world, to the common eye views are different, to the eyes of the road is often. Object-oriented thought is not only the wisdom of programming, but also the wisdom of life. Through life to understand the object-oriented wisdom, with object-oriented wisdom to guide life.

(some pictures are taken from how I explained OOD to my wife)

A single responsibility principle (Single-responsibility Principle) Definition: An object should contain only a single responsibility, and that responsibility is encapsulated in a class completely.

The dorm is not able to study hard, or to go to the library. This is a irrefutable truth! By countless students thousands of practice proved! I can not think of, the dormitory has a table has a chair, can go to bed nap, can get out of bed to read, hungry eat takeout, thirst drink grandmother, from a XI, why not? Later, because I study hard, and increased the knowledge of science and culture, this only to understand that our dormitory violates the "single principle of responsibility." In addition to not toilets, dormitories are both bedrooms and restaurants, as well as a study, kitchen, game room and chess room, and even a piano room and gym. I'll take a walk! You want to read a book, A in the ball, B in the bubble noodles, C in the bubble foot, there is a big wave of students at any time ready to come to visit, send small ads, delivery of takeout. Therefore, "reading" This "method" or "library" This "class", or "study room" This "class", because it is their responsibility, and they are a single duty. It is not that the dormitory is absolutely not to read, but because it takes on too much responsibility, these responsibilities in the concurrent implementation of the time will interfere with each other.

"Single responsibility Principle" in fact also contains a deep wisdom of life-anything to do well must be absorbed to do --the Yellow Emperor said "Shou one", Shun salary " only fine ", "Zhouyi" Yue "Zhen Yi", Lao Tzu said, "Hold One", The pipe "specificity", are teaching us this simple truth. Study or work, if you want to achieve, you have to "only fine". The reason why social production division of labor is now a high division of labor, also because of this reason. Big wave scouring sand, as a programmer, how to stand firm in the fierce competition, even invincible? There is no other way, a word: " refined one "! If you are still in a broad range of technology, but do not have the same expertise, then hurriedly according to the "single responsibility Principle" to reconstruct yourself!

Two · Open closure principle (open-closed Principle) Definition: Software entities should be open to extensions and closed for modifications.

If you want to make yourself look better, there are two ways. You can wear flower clothes, do hair, apply various kinds of frost to rub all kinds of powder, can wear a hat wearing gemajing wear red scarf, these are "expand". In addition, you can also cut double eyelid, open the corner of the eye, cushion the bridge of the nose to the chin pads, remove the biting muscle grinding cheek, and these are of course "modification." The reason to be open to the extension is to turn it off, because the changes are often dangerous and pay a price . Because of the failure of plastic surgery, the news of the operating table is not uncommon, as for Han Miaoko, Jocelyn-Widdenstein, fan, such as the example I do not raise, not afraid to scare everyone but their own fear. Very simple reason, a change is prone to bug, and often some unexpected Bug,duang ~ ~, plus stunt bug!

When it comes to this, the other thing that modifies the source code has to mention-genetically modified! When I remember the high school students, a fearsome name deeply carved into my young heart, the long-lasting new, that is-"bt poison protein "-My God! Sick poison Protein! This is a lot of poison! This psycho-toxic protein originated from "Bacillus thuringiensis", and later, great scientists discovered it, and cut its genetic fragments into genetically modified rice, genetically modified soybeans, genetically modified cotton (grain and cotton all to occupy!) ), How to look like a sci-fi movie in the strange Doctor to destroy the rhythm of the world ... Although the question of the safety of genetically modified crops is still controversial, the behavior of modifying the underlying source code of the creator makes us a programmer's concern . Who knows what kind of bug! will appear. Perhaps one day Duang ~ ~ of a bit, there is a Bugwith the stunt!

Extended reading: GMO debate Fudan professor defeats Cui Yongyuan

Three · dependency reversal principle (dependency-inversion Principle) Definition: High-level modules should not rely on the underlying modules, they should all rely on abstraction. Abstractions should not be dependent on detail, and detail should be dependent on abstraction.

A few years ago we often heard a saying, "all Money", is indeed a true portrayal of today's society. Angry friends please a little Ann, on the topic of modernity criticism after we talk, here or first to affirm the great achievements of capitalism. If we were primitive society, we had no money. All right, I want to eat meat! But our poor, no meat. And my neighbour raised a few pheasant, but "steal to rob to do son-in-law for" I am afraid all wrong, fortunately, I have a few daily Xuan iron a wonderful sword, so I said to the neighbor: "Take my peerless good sword for June a chicken, how?" "the neighbour said; , so I had a sumptuous lunch. One months later, I want to eat meat again! This time I took out just a good refining of a big Dan, to the neighbors: "Take me back to the back of the big still Dan change your chicken, not in?" ", the neighbor White me a glance, way:" I-want-drink-milk-milk! ”。 There is no way, in order to eat chicken, I ran to the next door of Qi Qi, the tribe, first find an old woman, with my back to the dead big also Dan changed her two jars, and take one of the jar with a local cow's uncle changed an altar milk, just with another jar to put back (or pretty witty!) ), and then the milk to the neighbors to drink, of course, the jar also had to return, I had the wish to eat a wild pheasant. Gradually, we all feel that it is too troublesome to change things! So, we are willing to exchange the most commonly used things, such as salt ah, cloth ah, axe ah, because these things basic house to use and later convenient for other things. However, some people taste light do not salt, some people do not want cloth yin, some people sick not axe, moreover, salt is easy to sprinkle, cloth easy to break, the axe easily rusty, so still inconvenient.

Then later, the money was born, its role is to act as a "Suphung". any commodity has its value, so-called exchange is nothing more than the value of their own exchange, if so, then find a thing to represent this abstract value of the amount, and other things to change it with a OK to! and does that not reflect the principle of "dependency reversal"?

Shi Rie Substitution principle (liskov-substituent Principe.) Definition: All references to base classes must be able to transparently use objects of their subclasses.

Aristotle's famous Three paragraph: "People are all dead, Socrates is human, so Socrates is dead." "Isn't that just a" richter substitution "? Similarly, you, I, he is-a people, according to the principle of substitution of the Richter scale is also "dead".

Everyone knows the truth of "the inherent death of a man," but not all of them know it. Tolstoy has a novel called "Ivan Iric's death", is about a small character, half a powerless, intimidated reasonably well, suddenly one day sick into the hospital, doctors and nurses, relatives and friends said, "You will be better." "At first he thought so, too. But it didn't take long for him to realize that he was going to be okay, and suddenly realized that "death" is a serious problem! We are always avoiding the "death" problem and perfunctory it. Just as everyone says to Fan Iric, "You'll be all right", like when you order a takeaway, the customer service always answers without hesitation, "it's been sent out!" ”。 Lu Xun has a famous novel-a peacock laid a big fat boy, one said: "This kid will be rich later!" "The master toasted," said one man, "This boy will be an official later!" "The master thanked him," said one, "The boy will surely die later." ", the mess sticks out! our avoidance of thinking about death is, in a sense, a way of escaping the thought of life.

Chinese taboo said "die" often replaced by said "lie Next", and "hundred Years" is like "3,000 feet straight down" of "3,000 feet", anyway is very long, we always feel "more days". But in fact, even the "dead" is nothing more than "after autumn Wenzhan". And the rest of the people will be at any time by natural disasters, traffic accidents, sudden illness, mishaps take life! Death is really close to us! Like a Damocles sword hanging over our heads. So Heidegger's definition of Deathis: "Death is the most self-contained, not related, knowing and uncertain, and exceeding possibility." " since death is a possibility, we have to plan our lives for the possibility." So Heidegger advocated "to die early", that is , "to die" life! Chairman Mao once said, "the Chinese are not afraid to die, but also afraid of difficulties?" "What else cannot be done in the face of" the end of a man's death "? Is there anything else you can't try? life is short, tendencies , really want to drab assortment mediocrities life after the discovery of "ever a knave, and then look back on the Hundred years of body"?

Refer to read my other blog : qingming season to rains-unknown death How do you know? --Born to death!  

Five • Interface Isolation principle (interface-segregation Principle) Definition: Clients should not rely on interfaces that it does not need.

The network quickly changes people's mental state, so that people are always in the "online (on-line)" state. Our thinking is crowdsourcing, published, no longer a center. We always see what other people are talking about, always listen to what the other people talk about, so forward, forward, and then forward. You see Chen Yao do public welfare, you and Ren Zhiqiang scold price, you learn kai-fu Lee to do their own, you in Fang Korea War in queued ... Your heart is the mell that they make up. But what about you? We live for others-for the expectations of parents, the hope of leadership, the comparison between colleagues and friends to live in a scramble, but you have to live for yourself? We are stimulated by a variety of desires--we want to live in a big house like others, driving a car, want to get ahead, there are 100 movies want to see, want to travel around the world, want to invest in financial management, want to buy all kinds of products that look pleasing to the eye, but you know what you need?

    

  we should not rely on interfaces that we do not need. when Socrates saw the extravagant items of Hawking, he said, "I don't need a lot of things!" Uncle Schopenhauer once said: "Just as a country that does not need or needs very little to import goods, is the luckiest country, likewise, if a person is abundant and rich and does not need to seek amusement from outside of himself, then this person is the luckiest person." because imported goods make the country expensive, rely on others, but also bring danger, create trouble. "Lao Tzu said:" Tone deaf deaf, colored blind, gallop the field is crazy. Chuang Tzu said: "Fall limb, deposed clever, I lost me." Confucius said "amending", Mencius said "reflexive and sincere", Zeng Zi said "a day provinces", Zen "Ming Xin", "Wang Yangming" to "conscience", from the pursuit of the external things confused, can really take care of the inner heart.

So please refactor yourself according to the "interface isolation principle"!

OO Wisdom in life--the five principles of object-oriented

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.