Process-oriented and object-oriented programming

Source: Internet
Author: User

programming methods can be divided into: process-oriented and object-oriented

Process oriented: process-oriented is our original way of programming, it is based on the computer's thinking mode of programming, the disadvantage is that it is difficult to use this programming when encountering more complex programs.
----------
Object-oriented: Everything is object, real life every real thing can be called object, object-oriented it is the way of thinking that mankind has ever had.

For example: We see a car first we will pay attention to its color, size, price, style and so on, these things called attributes or features. And then we'll think about what this car can do, like this, which is called a method or a behavior. And for none of us to see a departure we will not pay attention to how it was produced.



Object-oriented:

1. Attributes (features)

2. Method (behavior)
A class is an abstraction of an object that cannot be seen or touched, such as a computer, a student, an animal, or a class. And the object is the form of a class or a concrete instance is a real thing, such as Lenovo U200, Dell z5200 This is the specific manifestation of the computer class, is a real thing.
in philosophical terms, it is the relationship between universality (generality) and particularity (individuality). Universality in the particularity, and through the special manifestation, no particularity there is no universality. The two are interdependent and common, and are dialectical and unified.

here is how to use object-oriented programming ideas in the JAVASCRIP environment to write programs, the code is as follows:

function people (Name,age) {

THIS.name = name;

This.age = name;

This.run = function () {

Alert (this.name+ "Run and Run")

        }

    }

     var P1 = new People ("chubby");

    alert (p1.name+ "" +p1.age);

    p1.run ();


  inherit

Inheritance is the method and property that child elements can inherit from a parent element. The purpose of inheritance is to implement reuse, with inherited child elements not only having attributes and methods of the parent element but also adding some of their own properties.

Inheritance can be divided into false inheritance and true inheritance.



In order to achieve the purpose of inheritance can use object impersonation to achieve the purpose of inheritance

1. THIS.A = PEOPLE;THIS.A ( Name,age);d ELETE.THIS.A (where A is the impersonating object is not a true inheritance)

2. people.call (this.name,age)

3.  People.apply (this.[ Name,age])

prototype chain inheritance (true inheritance)


Man.prototype = new People;

This.constructor (name,age);

Process-oriented and object-oriented programming

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.