JavaScript-How to gracefully answer "what is object-oriented"?

Source: Internet
Author: User
I find that many interviewers like to ask this question (I am a student), but every time I feel that I am not answering the question satisfactorily.
My answer is often

    • Its design features are: inheritance, encapsulation, polymorphism;

    • From figurative to abstract. The property becomes the variable, and the behavior becomes the method;

However, the interviewer does not seem to be very satisfied, do not know the way the great God has a relatively elegant answer?

Reply content:

I find that many interviewers like to ask this question (I am a student), but every time I feel that I am not answering the question satisfactorily.
My answer is often

    • Its design features are: inheritance, encapsulation, polymorphism;

    • From figurative to abstract. The property becomes the variable, and the behavior becomes the method;

However, the interviewer does not seem to be very satisfied, do not know the way the great God has a relatively elegant answer?

The first answer is a programming paradigm .

Then say the specific description of the three features you're talking about, such as:

    • Inheritance: You can make subclasses reuse the variables and methods exposed by the parent class;

    • Encapsulation: Masks a range of details. Make external calls as long as you know the existence of this method;

    • Polymorphism: The method of the parent class inherits from the subclass and can have a different implementation mode after the child class;

Then you can talk about the advantages and disadvantages of object-oriented, then one thing is no absolute advantages and disadvantages, need a contrast. Therefore, you have to talk about the process-oriented programming idea .

Lost the article back.

Looked at the LZ problem was stepped on, I looked in the community, there is indeed a relevant answer. My article is a small supplement, if you have questions to point out.

Object-oriented thinking

Again with my work in the example of the answer to add, the previous time to do a very simple function, 点赞 is really a very simple function, but the function of the praise is not just once, the user can give other comments like, you can give the article like, you can give questions like, and so on. And after liking may trigger a series of events (notify the relevant users, etc.), initially I think there are three ways to

// 1.文章被用户点赞$article->votedBy($user);// 2.用户给某篇文章点赞$user->voteArticle($article);// 3.用户伸出大拇指给某篇文章点赞$user->thumbUp()->voteToArticle($article);//$user->thumbUp()->voteToDiscuss($discuss);

Finally I used the third writing, how to achieve, in your thumb out of the moment you know.

This is really an interesting question, haha. Of course, everyone will have a different understanding, after all, the concept of object-oriented is also hyped up.

My understanding consists of two areas:

    • One is object-oriented design;

    • One is object-oriented programming.

The core idea of object-oriented design is modularization, and the core idea of object-oriented programming is interface-oriented, object-oriented programming and a relative called object-based programming or prototype programming (JavaScript is). So object-oriented programming generally requires language-level support, as you can say about encapsulation, inheritance, and polymorphism.

Object-oriented concept when comparing fire, it is often said that software reuse is the direct embodiment of software reuse. But then it was discovered that more combinations should be used instead of inheritance, and then programming on the interface was fire-oriented.

It's a bit far.

All things are objects.

object-oriented

Everything is Object

Be sure to use examples to
such as animals-"Furu animals-" People, Lions, Tigers

Plus polymorphism, like it's going to be called

Inheritance, like Furu animals are all birth, and so on.

When you implement a project, you need to abstract the business into code, which is the programming paradigm, and object-oriented is one of them. Similar to process-oriented, functional programming.

The object-oriented feature is that 继承 多态 , 封装 .

Then the interviewer can start asking 继承 , 多态 and 封装 .

Perfect! ~~~

It's better to know what is the process-oriented, functional programming.

Self-contained, if he doesn't understand, you can go straight away, this interviewer is too dish!

JS said: All things are objects, objects are objects-no problem

Well, everything is on target.

Remember to read an answer in Zhihu his understanding is (in practice) the most important is the reuse of code.

Encapsulation: can be used directly in the encapsulated code block, which is reused.

Inheritance: Uses an existing property, which is reused.

Polymorphism: Different details, but still need to be reused on the basis of the first.

Do not discuss high-level program design, paradigm and other theoretical strong things, for writing code itself the most direct advantage and experience is that more reuse, the code becomes concise.

Face your object (commonly known as a man/girlfriend), put on an elegant posture, and then affectionately tell him/her, look at me ... This is gracefully object-oriented,

Packaging data and associated behaviors

Interesting question. I am also a student, talk about some of their own understanding.

An object-oriented feature is that it combines data and behavior (manipulation of data) more closely with real-world operational logic .
Why do you think it is compared to the traditional (process-oriented) and so on.

For example, the C language has a somewhat fragmented approach to data and behavior, with more emphasis on behavior. There is no concept of "object" in it, but a world full of action (function). The main function is to call the function, from the beginning of execution to the end of the results ... The most important thing in this world is all kinds of actions.

and C + + 's "object" is particularly like a thing, such as a person. Its world is a world full of objects. The main thing is the relationship between objects and objects (people and objects, people and people, etc.), or collisions that lead to the final result ... The most important thing in this world is all kinds of objects.

The object itself is carrying the data, carrying function, and the relationship between the objects has the world's operation. These two points, object-oriented program design and the real world more similar.

And the above "inheritance, encapsulation, polymorphism" and so on, it can also be simulated in the real world to better understand. Let me give you some examples ...

    • inheritance : Books & textbooks & computer Textbooks-This is the inheritance of the real world.

    • Package : Mobile-It's packaged, and when you use it, you don't have to know the circuit logic inside.

    • polymorphic: People. Look (Beautiful) & people. See (strong light)-the parameter types are different and the execution is different.

The object-oriented benefits are also easy to understand. One is to improve the understanding, because the object in accordance with the laws of human understanding of the world, in line with the common way of thinking; the second is easier to develop and maintain, the optimization of the system to a large extent is equal to the object data and functions of the re-understanding, on the original basis to modify something.

It's not right to ask you to criticize ...!

Do not rule out some interviewers themselves are very water, this is a big mother of the topic, sit together for a few days to talk about

Less to know, write more code

All things are objects.

  • 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.