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)
Classes and objects of primary knowledge
Everything in Python is an object, the nature of the type is the class, so whether you believe it or not, you've been using classes for a long time.
>>> Dict #类型dict就是类dict
<class ' Dict ' >
>>> d=dict (name= ' Eva ') #实例化
>>> d.pop (' name ') #向d发一条消息, executes the method pop of D
' Eva '
From the above example, the dictionary is a kind of data structure, I say the dictionary you know is that with {}, inside by the K-V key value pair of things, it also has some additions and deletions to change the method. But when I say a dictionary, do you know what the dictionary contains? No, so we say that for a class, it has the same characteristic attributes and methods.
and the specific {' name ': ' Eva '} This dictionary, which is a dictionary, can use all the methods of the dictionary, and it has a specific value, it is a Dictionary object. An object is a specific individual that has a real existence.
Another example, a little more popular, such as you now have a zoo, you want to describe the zoo, then every animal in the zoo is a class, tigers, swans, crocodiles, bears. They all have the same attributes, such as height, weight, birth time and variety, and a variety of actions, such as crocodiles swimming, swans flying, tigers running, and bears eating.
But the tiger bears are nothing specific, but a class of animals. Although they all have height and weight, you have no way of determining how much this value is. If this time gives you a specific tiger, and you are not dead, then you can give him a measure of height weigh weight, these values are not become specific? Then the specific tiger is a concrete example, but also an object. More than this one, in fact, each of the specific tigers have their own height and weight, then each tiger is a Tiger class object.
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.
def functionname (args):
' Function document String '
function body
‘‘‘
Class Name:
' class's document string '
Class Body
‘‘‘
#我们创建一个类
Class Data:
Pass
declaring classes
Classes and objects of primary knowledge
Everything in Python is an object, the nature of the type is the class, so whether you believe it or not, you've been using classes for a long time.
>>> Dict #类型dict就是类dict
<class ' Dict ' >
>>> d=dict (name= ' Eva ') #实例化
>>> d.pop (' name ') #向d发一条消息, executes the method pop of D
' Eva '
From the above example, the dictionary is a kind of data structure, I say the dictionary you know is that with {}, inside by the K-V key value pair of things, it also has some additions and deletions to change the method. But when I say a dictionary, do you know what the dictionary contains? No, so we say that for a class, it has the same characteristic attributes and methods.
and the specific {' name ': ' Eva '} This dictionary, which is a dictionary, can use all the methods of the dictionary, and it has a specific value, it is a Dictionary object. An object is a specific individual that has a real existence.
Another example, a little more popular, such as you now have a zoo, you want to describe the zoo, then every animal in the zoo is a class, tigers, swans, crocodiles, bears. They all have the same attributes, such as height, weight, birth time and variety, and a variety of actions, such as crocodiles swimming, swans flying, tigers running, and bears eating.
But the tiger bears are nothing specific, but a class of animals. Although they all have height and weight, you have no way of determining how much this value is. If this time gives you a specific tiger, and you are not dead, then you can give him a measure of height weigh weight, these values are not become specific? Then the specific tiger is a concrete example, but also an object. More than this one, in fact, each of the specific tigers have their own height and weight, then each tiger is a Tiger class object.
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.
A class has two functions: property Reference and instantiation
Class Person: #定义一个人类
role = ' person ' #人的角色属性都是人
def walk (self): #人都可以走路, that is, there is a way to walk
Print ("Person is walking ...")
Print (Person.role) #查看人的role属性
Print (Person.walk) #引用人的走路方法, note that this is not a call to the
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
Class Person: #定义一个人类
role = ' person ' #人的角色属性都是人
def __init__ (self,name):
Self.name = name # Each character has its own nickname;
def walk (self): #人都可以走路, that is, there is a way to walk
Print ("Person is walking ...")
Print (Person.role) #查看人的role属性
Print (Person.walk) #引用人的走路方法, note that this is not a call to the
The process of instantiating is a class-to-object procedure
Originally we had only one person class, in this process, produced an egg object, has its own specific name, attack and health value.
Syntax: Object name = class Name (parameter)
Egg = person (' Egon ') #类名 () is equal to executing person.__init__ ()
#执行完__init__ () returns an object. This object is similar to a dictionary and has some properties and methods that belong to the person itself.
#你可以偷偷的理解: Egg = {' name ': ' Egon ', ' Walk ': Walk}
Print (egg.name) #查看属性直接 object name. Property name
Print (Egg.walk ()) #调用方法, object name. Method Name ()
Self: Automatically passes the object/instance itself to the first parameter of __init__ when instantiated, and you can give him an individual name, but the normal person will not do so.
Because you don't know anyone because you're blind.
A: Where do the properties of the class we define are stored? There are two ways of viewing
Dir (class name): A list of names is isolated
The class name. __DICT__: A dictionary is found, key is a property name, value is a property value
Second: Special class properties
Class name The name of the __name__# class (string)
The document string for the class name. __doc__# class
Class name the first parent class of the __base__# class (Speaking of inheritance)
The class name is a tuple of all the parent classes of the __bases__# class (Speaking of inheritance)
Class name. Dictionary properties for the __dict__# class
Class name. The module where the __module__# class is defined
Class name the class that corresponds to the __class__# instance (in the modern class only)
Object
Object is an example of a class that actually exists, that is, an instance
Object/instance has only one function: Property reference
Of course, you can also refer to a method, because the method is also a property, but a function-like property, we also call it dynamic properties.
Referencing a dynamic property is not the way to do this, but to call the method and call the function is the same, you need to add parentheses after the
I know in the class that you may still have a lot to understand. Then we use the function to explain this class Ah, the object is what is a what, you secretly use this understanding is good, do not tell others
Python Seventh Day