程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

No action, no intention Python object-oriented-45. Object oriented programming

編輯:Python
Catalog
  • 1、 The concept of object-oriented programming
  • 2、 The difference between object-oriented programming and process oriented programming
    • (1) Process oriented programming
    • (2) object-oriented programming
  • 3、 Object oriented understanding
  • 4、Python Object - oriented programming
  • 5、 Several core features of object-oriented

1、 The concept of object-oriented programming

  • Python It has been an object-oriented language since the beginning of design , Because of that , We must have heard of it Python in Everything is the object That's what I'm saying .
  • object-oriented programming (Object-oriented Programming, abbreviation OOP), It's a kind of programming idea .
  • Object oriented programming regards object as the basic unit of program , An object contains data ( attribute ) And functions that manipulate data .
  • In the idea of object-oriented design , Think of a program as the result of multiple objects working together . The program is divided into several sub modules , Then, multiple objects complete their respective modules, and finally realize the function of the program .
  • object-oriented programming , Is an idea of encapsulating code .
  • Object oriented programming is developed on the basis of process oriented programming , It is more flexible and extensible than process oriented programming .

2、 The difference between object-oriented programming and process oriented programming

(1) Process oriented programming

Process oriented programming takes function as the basic unit of program . When programming , Write groups of functions , Then execute the functions step by step , That is, the sequential execution of a set of functions . To simplify programming , Process oriented functions continue to be divided into subfunctions , That is to cut large function into small function to reduce the complexity of the system .

Process oriented programming , The core is " The process ", Focus on the steps to solve the problem , That is, what to do first and then what to do . Process oriented programming is like a pipeline , It's a kind of mechanical thinking . If program starts with the solving a big problem , Process oriented programming thinking will decompose a big problem into many small problems , These small problems can be further decomposed , Until the small problem is simple enough to be solved in one small step .

  1. advantage :

    • It greatly reduces the complexity of writing programs , Just follow the steps , Just stack the code .
    • Complex problems flow , And simplify it .
  2. shortcoming :
    • A set of assembly lines or processes is to solve a problem , If one of the methods is modified , Then other components should be modified accordingly .
    • That is to say, there are problems , Pull one hair and move the whole body .

(2) object-oriented programming

The object-oriented programming takes the object as the basic unit of the program , When programming , Design many objects ( Class ), Each object has the ability to solve some corresponding problems . Our object-oriented programming is based on process oriented programming , Class is the function ( Small steps ) It was packaged , As long as you find the specific class , Create objects , You can call the specific functions .

Object oriented is a thinking mode used to solve problems , In later development , Look for someone first , Call specific functions in the object . If there is really no object that can complete the requirements , Then define your own class , And define the required functions into the object , Convenient for future use .

  1. advantage :

    • Object oriented is an idea that is more in line with people's thinking habits .
    • The process oriented is more embodied in the executor , In object-oriented, it is more reflected in the commander , Command objects to do things .
    • Object oriented simplifies complex problems .
    • Because of the encapsulation of object-oriented 、 Inherit 、 Characteristics of polymorphism , Make the system more flexible 、 Easy maintenance 、 Easy to reuse 、 Easy to expand , You can design low coupling systems .
  2. shortcoming :
    • Performance is lower than process oriented .
    • As the saying goes, there must be gains and losses , But in today's hardware crazy development , When the system becomes more and more complex , weigh the advantages and disadvantages , We choose object-oriented programming .

3、 Object oriented understanding

Object oriented is an abstract programming idea , There is an idea in many programming languages .

1) demand

for example : Wash the clothes

reflection : There are several ways to do laundry ?

answer : Hand wash and Machine wash .

2) Process oriented laundry

Hand washing is equivalent to washing clothes facing the process :

  • Find Basin
  • water
  • Add washing powder
  • soak
  • Scrub
  • Wring out water
  • Pour water
  • Airing
  • Put it away and fold it

After so many steps , You finally finished your clothes , But I'm exhausted .

3) Object oriented laundry

Machine washing is equivalent to object-oriented washing clothes .

This washing machine is the object , Put the clothes in the washing machine :

  • Turn on the washing machine ( Class to create objects )
  • Wash the clothes ( Call method in object )
    • Washing machine -- Add water
    • Washing machine -- Add washing powder
    • Washing machine -- soak
    • Washing machine -- Scrub
    • Washing machine -- dehydration
    • Washing machine -- Drainage
    • Washing machine -- dry
  • Turn off the washing machine ( When the program is finished, put away your clothes )

You sit by the window and watch the sunset , Sigh that life is so beautiful !

4) summary :

reflection : Compare two ways of washing clothes , Which way is simpler ?

answer : Machine washing is simpler .

Machine wash only needs to find a washing machine , Add simple operations to complete the laundry work , And don't care what's going on inside the washing machine .

Object oriented is to treat programming as a thing , For the outside world , Things are used directly , Don't worry about his internal situation . Programming is about setting what things can do .

4、Python Object - oriented programming

Object oriented programming is the use of class and object To create various models , To realize the description of the real world .

The reason for using object-oriented programming :

  • On the one hand, it can make the maintenance and expansion of programs easier , And can greatly improve the efficiency of program development .
  • in addition , Object oriented programs make it easier for people to understand your code logic , To make team development more leisurely .

5、 Several core features of object-oriented

  1. Class class : A class refers to the same feature extraction of the same thing , Extract the same attribute method and define it in the class .
  2. Object object : An object is an instance of a class , The object is concrete , Class is abstract .
  3. encapsulation : Working details of hiding objects from the outside world .
  4. Inherit : A subclass inherits the fields and methods of the base class .
  5. polymorphic : Use the same operation for objects of different classes .

『 No action, no heart 』Python object-oriented — 45、 More articles on object-oriented programming

  1. 『 No action, no heart 』Python Basics — 2、 The difference between compiled and interpreted languages

    Catalog 1. What is computer language 2. Compiler language and interpretive language in high level language (1) Compiler language (2) Explanatory language (3) Compiled language and interpreted language execution process 3. Knowledge expansion : 4. About Python 1. What is computer language ...

  2. 『 No action, no heart 』Python Basics — 3、 build Python development environment

    Catalog 1.Python Introduction to development environment 2.Python The classification of interpreters 3. download Python Interpreter 4. install Python Interpreter 5.Python Interpreter validation 1.Python Introduction to development environment So-called " Desire for work ...

  3. 『 No action, no heart 』Python Basics — 4、Python Common debugging tools for code

    Catalog 1.Python The interaction mode of 2.IDLE Instructions for use of tools 3.Sublime3 Installation and configuration of tools (1)Sublime3 Installation (2)Sublime3 Configuration of 4. Use Sublime Write and debug Pytho ...

  4. 『 No action, no heart 』Python Basics — 5、Python Installation and use of development tools

    Catalog 1.Pycharm download 2.Pycharm install 3.PyCharm Interface is introduced 4. Basic use (1) newly build Python project (2) To write Python Code (3) Execute the code to see the results (4) Set up PyCharm ...

  5. 『 No action, no heart 』Python Basics — 6、Python Notes

    Catalog 1. The function of annotation 2. Classification of notes Single-line comments Multiline comment 3. Notes 4. When do I need to use comments 5. summary Tips : Finished the preparatory work ahead , The following article begins to introduce Python The basic grammar of . Python ...

  6. 『 No action, no heart 』Python Basics — 7、Python The variable of

    Catalog 1. Definition of variables 2.Python Variable description 3.Python Define variables in (1) Definition grammar (2) Identifier definition rules (3) Built in keywords (4) Identifier naming habits 4. Using variables 1. Definition of variables In the program , The data are all ...

  7. 『 No action, no heart 』Python Basics — 8、Python Data types in ( The number 、 Boolean 、 character string )

    Catalog 1. Data type introduction 2. Numerical type (Number) 3. Boolean type (bool) 4.None( Null value ) 5. Constant 6. character string (String) 1. Data type introduction (1) What is data type In the life , What we use everyday ...

  8. 『 No action, no heart 』Python Basics — 9、Python Encoding and escaping of strings

    Catalog 1. See variable types 2. Escape character (1) Escape character description (2) Example (3) Comparison table of common escape characters 3. Character encoding (1) Introduction to character encoding (2)Python Character encoding in (3) The encoding format is applied to different scenes Tips : On ...

  9. 『 No action, no heart 』Python Basics — 10、Python Formatted output of string

    Catalog 1. What is formatted output 2.Python Five ways to format output Mode one : Use... Between strings + No. splices Mode two :print() Function can output multiple strings at the same time Mode three : Placeholder method Mode 4 :f Formatting method ( recommend ) Methods five ...

  10. 『 No action, no heart 』Python Basics — 11、Python Data type conversion in

    Catalog 1. Why data type conversion 2. The essence of data type conversion 3. Functions used in data type conversion 4. Common data type conversion function (1)int() function (2)float() function (3)str() function (4)bool( ...

Random recommendation

  1. HTML5 Explore datalist Research

    A recent project requires something like Taobao , Baidu search when the automatic retrieval scheme . Naturally thought of using datalist label . But I met a bug, After two days of research . I have some results to share with you ~~ First of all to see bug Well !~ Because the first test of the project is to use 36 ...

  2. Swift-5- Process control

    // Playground - noun: a place where people can play import UIKit // For-In loop // 1 Traversing the number range ... { prin ...

  3. eclipse mingw cpp development environment

    Eclipse Development c++ contrast : Microsoft VC++6.0: Too old , Yes win7 Not compatible , Now Microsoft's Visual Studio: The package is too large , several G, A bunch of stuff you don't need , Asking for money , teach It's troublesome to apply for Education Edition DOS Next ...

  4. arcgis api for js Entry development series 15 typhoon tracks

    The last one realized demo Path analysis of the nearest facility point on the map , Typhoon tracks are added in this chapter , The screenshot is as follows : The following is a brief introduction to relevant knowledge points : cordon Cordon coordinate set : var lineArr24=[[127,34],[127,21],[11 ...

  5. es6 Object.assign

    ES6 Object.assign One . Basic usage Object.assign Method is used to convert the source object (source) All enumerable properties of , Copy to target object (target). It requires at least two objects as parameters , The first parameter is the target ...

  6. 51nod 1617 Parity array

    Portal Come back and have a look 51nod, Find yourself falling into rank4 了 , Cut to the point and answer rank3. You can't do it at a glance , This kind of thing should find rules slowly …… Then I see that the data range is actually small , It should be a single time log Of , Is it possible to divide and conquer . #inc ...

  7. JavaScript Object array based on a property sort Up and down sort

    1. Customize a comparator , Its parameters are the attributes to be sorted . 2. Pass the comparator with parameters into sort(). var data = [    {name: "Bruce", age: 23, id: 16 ...

  8. Win10 Use the command to repair the system necrotic point

    My computer win10 After the system has been upgraded many times , It often happens that all settings are sometimes disabled solve : C:\WINDOWS\system32>sfc /SCANNOW Start the system scan . This process will take some time . Start system scanning ...

  9. Git Management project

    A very small one HTML project , Use .Git To record and track this project . Including the following : Create a version Library . Add and modify files . Create a new branch . Tag and organize the version Library . Clone version Library . Create a version Library Creating a Repos ...

  10. Win10 Virtual desktop

    We can create multiple desktops , The window tasks running on each desktop do not interfere with each other , This is the virtual desktop Create a virtual desktop :Win + Ctrl + D View virtual desktop :Win + Tab Delete current virtual desktop :Win + Ctrl + F4 Switch to ...


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved