Programming is a programmer with a specific syntax + data structure + algorithm composed of code to tell the calculator how to perform the task of the process, a programmer in order to get a result of a set of instruction set, of course, the implementation of a task can have many different ways, the characteristics of these different programming methods, The type of programming that can be summed up is the programming paradigm, where most languages only support one way of programming, and of course there are languages that support multiple programming paradigms at the same time.
Common Programming Paradigms:
1. Process oriented: From top to bottom code based on business logic.
2. Function: A function is encapsulated in a function, it is convenient to use the function only when it is not necessary to write duplicate code.
3. Object-oriented: classify and encapsulate functions to make development "faster, better and stronger".
There is no good or bad language, the programming paradigm is not good or bad, the deciding factor lies in what scenario you use, what language is right for you, and how the developer's own level is.
Process-oriented programming (procedural programming)
is the program from the top to the next step, to solve the problem from beginning to end, the basic design idea is that the program is to solve a big problem, and then a big problem into a lot of small problems or sub-processes, these sub-processes continue to decompose, until the small problem can be solved in a small step range.
To give a typical process-oriented example, database backup, divided into three steps, connecting the database, backing up the database, testing the backup file availability.
1 defdb_conn ():2 Print('Connectin db ...')3 4 defDb_backup (dbname):5 Print('Export Database ...', dbname)6 Print('reduce the backup file package, move to the appropriate directory ...')7 8 defdb_backup_test ():9 Print('reduce the backup file into the test library to see if the import was successful')Ten One defMain (): A Db_conn () -Db_backup ('Mysqlname') - db_backup_test () the - if __name__=='__main__': -Main ()
If you want to modify the program, you have to change the part of the dependent parts you have to follow the changes, for example, if the program at the beginning you set a variable value of 1, but if the other sub-process depends on the value of 1 of the variable to run correctly, if you change this variable, then this process you have to modify, If there is another subroutine that relies on this sub-process, it will have a series of effects, which will be more difficult to maintain as the program grows larger and higher.
So we generally think that if you just write some simple scripts to do some one-off tasks, it's great to use a process-oriented approach, but if the task you're dealing with is complex and needs to be iterative and maintainable, it's the most convenient way to use object-oriented.
Object-oriented (object-oriented programming)
OOP programming is the use of ' class ' and ' object ' to create models to achieve a real-world description, using object-oriented reasons, on the one hand because he can make the maintenance and extension of the program easier, and can greatly improve the efficiency of program development, on the other hand, Object-oriented programs can make it easier for others to understand your code logic, so that team development is easy.
Several core features of object-oriented are as follows:
A class is an abstraction, blueprint, and prototype of a class of objects that have the same properties. The properties that these objects have are defined in the class, in a common way.
An object is an instantiated instance of a class, a class must be instantiated before it can be called in the program, a class can instantiate multiple objects, each object can also have different properties, like human refers to everyone, each person refers to the specific object, there are similarities between people, there are also different.
The assignment of data in a class, internal invocation is transparent to external users, which makes the class A capsule or container containing such data and methods.
A class can derive a subclass, a property defined inside the parent class, and the method automatically inherits from the Quilt class.
Polymorphism is an important feature of object-oriented, the popular point is "an interface, a variety of implementations", refers to a base class derived from a number of different subclasses, and each subclass inherits the same method name, but also the parent class method to do a different implementation, this is the same thing shows a variety of forms.
Programming is actually the process of abstracting a specific world, which is a manifestation of abstraction, abstracting the common denominator of a series of specific things, and then, through this abstract thing, dialogue with different concrete things.
Sending the same message to different classes of objects will behave differently, for example, when your boss lets all employees start working at 9 o'clock, he says "Get started" at 9, instead of saying "start a sales job" to the salesperson, "Start technical work" for the technician, because "employees" is an abstract thing, as long as the employees can begin to work, he knows this can be, as for each employee, of course, will do their own duties, do their own work.
Polymorphism allows the object of a subclass to be used as an object of the parent class, a reference to a parent type to an object of the subtype, a method to invoke the subtype, and the code for referencing and invoking the method is determined before it is compiled, and the object pointed to by the reference can be dynamically bound during run time.
Object Oriented (i)