Python Object-oriented initialization

Source: Internet
Author: User

Python Object-oriented initial

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.

Disadvantages are: poor controllability, unable to process-oriented programming pipeline can be very accurate prediction of the problem of the processing process and results, the object-oriented program once the beginning of the interaction between the object to solve the problem , even God can not predict the final 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: Class-to-object procedure

Related knowledge of the class:

Statement:

def functionname (args):      ' function Document String '        ' class class name: ' Class ' document string ' body ' ' #         We create a class   Data:    Pass

Property:

classPerson:#Define a humanRole =' Person'  #People's role attributes are people    defWalk (self):#people can walk, that is, there is a way to walk        Print("Person is walking ...")Print(Person.role)#View the Role property of a personPrint(Person.walk)#referring to the way people walk, note that this is not the call

Instantiation: The class name parentheses are instantiated, automatically triggering the run of the __INIT__ function, which can be used to customize each instance of its own characteristics

classPerson:#Define a humanRole =' Person'  #People's role attributes are people    def __init__(self,name): Self.name= Name#each character has its own nickname;            defWalk (self):#people can walk, that is, there is a way to walk        Print("Person is walking ...")Print(Person.role)#View the Role property of a personPrint(Person.walk)#referring to the way people walk, note that this is not the call

Python Object-oriented initialization

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.