Object-oriented Python

Source: Internet
Author: User

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 the object-oriented programming of the good place

Object-oriented programming is not all. For a software quality, object-oriented programming is just to solve extensibility.

Extracting similar parts from a set of objects is a combination of features and skills that all objects of a class have.

In Python, a variable represents a feature, a function represents a skill, and a class is a combination of a variable and a function, and an object is a combination of a variable and a method (a function that points to a class).

A class is a combination of data and a function, which is called a property of a class

A class has two functions: property Reference and instantiation

>>> garen.camp # Reference class's Data property, which is shared with all objects/instances

'demacia'

>>> Garen.attack # A function property of a reference class that also shares

<function Garen.attack at 0x101356510>

>>> garen.name='garen' # Add Property

>>> del garen.name # Delete property

Object/instance has only one function: Property reference   

The object/instance itself has only data properties, But Python's class mechanism binds a function of a class to an object, called a method of an object, or a binding method, a binding method uniquely binds an object, and a method of the same class binds to a different object,

different methods, memory addresses are not the same

The special thing about object binding methods is that Obj.func () passes obj to the first argument of Func.

Creating an object/instance creates an object/instance namespace that holds the name of the object/instance, called the object/instance property

In the Obj.name will first find the name in Obj's own namespace, can not find the class to find, the class can not find the parent class ... Throw an exception if you can't find it at the end

Object-oriented Python

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.