python--Object-oriented

Source: Internet
Author: User

Process-oriented VS object-oriented

Process-oriented program design is the core of process (pipeline thinking), the process is to solve the problem of the steps, process-oriented design is like a well-designed pipeline, consider when to deal with what things.

The advantage is that it greatly reduces the complexity of the writing process, and only needs to stack the code along the steps to be performed.

The disadvantage is: a set of pipeline or process is to solve a problem, code reaching.

Application scenario: Once you have completed a very rarely changed scenario, the notable examples are Linux kernel, git, and Apache HTTP server.

Object-oriented program design is the core of the object (God-like thinking), to understand what the object is, we must regard themselves as God, God in the eyes of the world exists in all things are objects, not exist can also be created. Object-oriented programming good for example, to design a journey to the east, the Tathagata to solve the problem is to pass the scriptures to the Eastern Earth Datang, the Tathagata thought to solve this problem requires four people: Tang's monk, Sha Monk, Pig Eight commandments, Monkey King, everyone has their own characteristics and skills (this is the concept of objects, Characteristics and skills corresponding to the object's properties and methods, but this is not fun, so the Tathagata arranged a group of ghosts and goblins, in order to prevent the four people in the study on the road was killed, and arranged a group of immortal escort, these are objects. Then the beginning of the lessons, master and master Four with ghosts and demons to each other until the end of the canon. The Tathagata does not control the four people follow what process to take.

Object-oriented program design

The advantage is that it solves the extensibility of the program. A single modification of an object is immediately reflected in the entire system, such as the character of a character parameter in the game and the ability to modify it easily.

Cons: Poor controllability, inability to process-oriented programming pipelining can accurately predict the problem of the processing process and results, the object-oriented program once started by the interaction between the object to solve the problem , even God can not predict the end result. So we often see a game of people changes in a certain parameter is likely to lead to the ability of the bully to appear, a knife to kill 3 people, the game is out of balance.

Application scenario: frequently changing requirements of the software, the general needs of the changes are concentrated in the user layer, Internet applications, enterprise internal software, games, etc. are object-oriented programming is a good place to play.

Object-oriented programming in Python is not all.

Object-oriented programming makes it easier to maintain and extend programs, and can greatly improve program development efficiency, and the object-oriented program makes it easier for people to understand your code logic, making team development easier.

Learn about nouns: classes, objects, instances, instantiation

Class: A category of things (people, dogs, tigers) with the same characteristics

Object/instance: A specific thing (next door Jen, Downstairs wong Choy)

Instantiation: The class-to-object process (which is not apparent in life, we explain it later)

In Python, a variable represents a feature, a function represents a skill, and thus a class of things with the same characteristics and skills is a ' class ', and the object is the specific one in this category.

Creating a class creates a namespace for a class that stores all the names defined in the class, called Properties of the class

The class has two properties: static property and dynamic property

    • A static property is a variable that is defined directly in the class
    • A dynamic property is a method defined in a class

Class Name:    def __init__ (self, parameter 1, parameter 2): Self        . Property of the Object 1 = parameter 1 self        . property of Object 2 = parameter 2    def method name (self):p    Method Name 2 (self):p the name  of the #对象就是实例, which represents a specific thing                  #类名 (): Class name + parenthesis is the instantiation of a class, equivalent to invoking the __init__ method                  #括号里传参数, The parameter does not need to pass self, and the other is #结果返回一个对象对象名 corresponding to the formal parameter one by one in Init                  . The object's property 1 #查看对象的属性, directly with the object name. The name of the object.   method Name ()     #调用类中的方法, directly with the object name. Method Name () can be

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