How to learn object-oriented programming

Source: Internet
Author: User

The basic concept of object-oriented (1) ObjectObjects are anything that people want to study, from the simplest integers to the complex planes that can be considered objects, not only to represent specific things, but also to represent abstract rules, plans, or events. (2) The state and behavior of the objectAn object has a state, and an object uses data values to describe its state. Objects also have actions that change the state of an object, which is the behavior of the object. Objects enable data and operations to be combined to encapsulate data and operations in an object's unity (3) classAn abstraction of an object of the same or similar nature is a class. Thus, an object's abstraction is a class, the materialization of a class is an object, or an instance of a class is an object. A class has attributes, which are abstractions of the state of an object, and data structures that describe the properties of a class. A class has an operation that is an abstraction of the behavior of an object, described by the operation name and the method that implements it. (4) structure of the classThere are several classes in the objective world, and there are certain structural relationships between these classes. There are usually two main structural relationships, that is, general-concrete structural relationship, whole-part structure relationship. ① General--specific structure is called classification structure, can also be said to be "or" relationship, or "is a" relationship. ② whole--part of the structure is called the assembly structure, the relationship between them is a "and" relationship, or "has a" relationship. (5) Messages and methodsThe structure of communication between objects is called a message. In an object's operation, when a message is sent to an object, the message contains information that receives the object to perform some action. Send a message at least to include the name of the object that is accepting the message, the name of the message sent to the object (that is, the object name, the method name). Parameters are generally described, either as variable names known to the object that knows the message, or as global variable names that all objects know. The implementation of operations in a class is called a method, a method has a method name, a parameter, a method body. Message delivery is shown in 10-1. Characteristics (1) Uniqueness of objectsEach object has its own unique identity, through which the corresponding object can be found. Throughout the life of an object, its identity does not change, and different objects cannot have the same identity. (2) ClassificationClassification is the abstraction of objects that have consistent data structures (properties) and behaviors (operations) into classes. A class is an abstraction that reflects the important nature of the application and ignores other extraneous content. The division of any class is subjective, but it must be related to the specific application. (3) Inheritance
Inheritance is the mechanism by which subclasses automatically share data structures and methods of the parent class, which is a relationship between classes. When defining and implementing a class, it can be done on top of an already existing class, taking the content defined by the existing class as its own content, and adding a number of new content. Inheritance isObject-Oriented programmingLanguage differs from the most important features of other languages, which are not in other languages. In a class hierarchy, a subclass inherits only the data structure and methods of a parent class, which is called a single-inheritance. In the class hierarchy, subclasses inherit the data structure and methods of multiple parent classes, called multiple inheritance. In software development, the inheritance of the class makes the software open and extensible, which is an effective method of information organization and classification, which simplifies the creation of objects and classes, and adds the codeRepeatable Usability。 With inheritance, the hierarchical structure of the class's specification is provided. Through the inheritance of the class, the common features can be shared, and the reusability of the software is improved. (4) polymorphism
Polymorphism refers to the same operation or function, the process can be used on multiple types of objects and obtain different results. Different objects, receiving the same message can produce different results, a phenomenon known as polymorphism. Polymorphism allows each object to respond to a common message in a way that suits itself. Polymorphism enhances the flexibility and reusability of software. Object-Type Programming
1. To object-oriented, the first step is to process.
2. The so-called object-oriented is the basic human thinking method;
3. Characteristics---i.e. attributes;
4. The act---namely the method;
5. Objects and Classes
-Objects with the same properties and methods are grouped into one category;
-An object is an instance of a class that exists in real life;
-A class is an abstraction of an object;

Inherited:
     function people (name,age) {     this.name = name;     This.age = age;     This.show = function () {     console.log ("My name is:" +this.name+ "my Age is:" +this.age);}     }            Function Man (name,age) {    //Object Impersonating Method 1    //this.inhert = people;    This.inhert (name,age);    Delete This.inhert;    Object Impersonating Method 2    //people.call (this,name,age);    Object Impersonating Method 3    //people.apply (This,[name,age]);    this.name = name;    This.age = age;    }    Man.prototype = new People ();    var man1 = new Man ("Zhang Fei");    Man1.show ();            Console.log (man1 instanceof people);

During the learning process, we would like to thank the annotations to help understand, because I feel that object-oriented looks very easy, but to cultivate this kind of programming idea is not overnight can achieve. The advantages of learning this idea are: 1, easy to maintain
Object-oriented design of the structure, high readability, due to the existence of inheritance, even if the need to change, then maintenance is only in the local module, so maintenance is very convenient and low cost.
2. High quality
At design time, you can reuse existing classes that have been tested in the field of previous projects to make the system meet business requirements and have high quality.
3. High efficiency
In software development, according to the needs of the design of the real world of things to abstract, produce classes. Using this method to solve the problem, close to the daily life and the natural way of thinking, is bound to improve the efficiency and quality of software development.
4. Easy to expand
Due to the characteristics of inheritance, encapsulation and polymorphism, the system structure of high cohesion and low coupling is designed naturally, which makes the system more flexible, easier to expand and less cost.

How to learn 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.