Object-oriented python (i)

Source: Internet
Author: User

Python programming consists of three stages:

    1. Process-oriented programming: From top to bottom based on business logic
    2. Functional Programming: Function encapsulation of a function, the use of the function can be called, reduce the amount of code duplication
    3. 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

    1. Packaging
    2. Inherited
    3. Polymorphic
Packaging

Encapsulation is actually divided into two steps: encapsulation and invocation!

Object-oriented python (i)

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.