Python programming consists of three stages:
- Process-oriented programming: From top to bottom based on business logic
- Functional Programming: Function encapsulation of a function, the use of the function can be called, reduce the amount of code duplication
- Object-oriented Programming: classifying and encapsulating functions
In theory, we despise process-oriented programming, so the question is, which is functional programming and object-oriented programming?
Let's take a look at two features:
- Function programming, logic clear, simple, for the project, maintenance difficulties, functional programming advocated by the solution is that the data is immutable, there is no constant change in the state, thereby reducing the complexity.
- Object-oriented, chatty, complex, for large projects, long development cycle, theoretically long-term maintenance simple, in fact, a mess ... Object-oriented programming is particularly suitable for processing business logic, so it is widely used in current software development.
Summarize
So what is the case with object-oriented? when some functions have the same parameters, you can use the object-oriented way, the parameter value of a one-time package to the object, later to take the value of the object can be, I think this is the simplest answer for beginners like me ...
When do you use functional programming? separate and no-shared data between functions
Creation of classes and objects
The object-oriented programming approach requires the use of classes and objects to implement:
- A class can be seen as a template, a template that contains multiple functions, functions that implement certain functions
- An object is an instance created from a template that can invoke a function function in a class through an instance object
- Class is a keyword that declares the creation of a class
- Class followed by (), which represents the creation of the object
- When a function is defined in a class, the first argument must be self, and a function in a class is called a method
Three main features of object-oriented
Not smoking and drinking perm .... Is
- Packaging
- Inherited
- Polymorphic
Packaging
Encapsulation is actually divided into two steps: encapsulation and invocation!
Object-oriented python (i)