Object-oriented concepts, the initialization method

A object-oriented concepts:

What is object-oriented?

  Object-oriented programming is a kind of thinking is summed up the experience of predecessors, the programmer knows how to write better programs.

The core is the object of the program is a collection of column objects, the programmer is responsible for scheduling these objects to interact with the task.

  Object-oriented:

    Have the skills to find objects loaded elephant.

  Advantages: scalability, flexibility, high reusability

  Disadvantages: high complexity procedures, not ready to predict results

  Usage scenarios: the user directly to a program normally. For example QQ, micro-letter

What is the process-oriented programming ideas?

   The core concern is the process, step by step process is executed

  Process-oriented:

    1. Open the refrigerator;

    2. Load elephant

    3. Close the refrigerator

  Advantages: clear logic, simplifying complex issues, process

  Disadvantages: poor scalability, maintainability

  Usage scenarios: a low expansion program requirements. For example kernel, Git, computer

 

Second, the concept of classes and objects

  Categories: type, it is an abstract concept

    Is a collection of columns has the same features and the same behavior of the object

  Object:

    Have a thing exists, they have their own characteristics and behavior

    Object is the complex characteristics and skills

  Relationship between the two:

    Class contains column objects,

    The object belongs to a class

  A summary conclusion: When using object-oriented programming, the first step is to think about what kind of object needs, what kind of an object with characteristics and behavior, which summed up the type of information required in accordance with

 

Third, how to create classes and objects

  Class definition syntax:

class name of the class:
     # content class describes the attributes and skills 
    # description attribute with variable 
    # describe the behavior of a function 

# class name written specification above all see the name known Italian names are big hump nomenclature   
# Hump is the word capitalized large hump is the first letter capitalized, small hump is the first letter lowercase

  Create an object syntax:

class the Person:
     Pass 

# create the object 
p = Person ()

 

 

IV. Class of property

  Properties wording:

    Properties can be written in class, class attributes are common to all objects

    Properties can also be written in an object, object properties, each object is unique

  Deletions difference change properties:

Increase property 
object variable name. Attribute name = attribute value
 
to delete attribute
del object variable name attribute name modify objects. Attribute = New Value View property access is the object of all the properties print (object. __Dict__ ) class information access objects print (Object. __class__ )  

  Property search order  

    ps: If the same property, to access objects and object classes exist, if there is no place in the class to ask  

 

Fifth, the initialization method

  initialization method __init__ method is called, is essentially a function

  Features:

    1, when the object is instantiated, the init method of automatically

    2, will automatically object as the first argument, the parameter name is self, self can be another name, but it is not recommended to change

  Function: Users assign initial values ​​to the object

  The essence of the object is to speak into data and data processing functions together, so to get an object on both his function data and processing data to be processed

 

Sixth, binding and non-binding approach method

  Bound method object:

    The method of the default class are bound object method, which is special because, when the object will automatically call the function of the incoming object itself, as the first parameter.

    When the class name to call him is a normal function, there are several parameters, there are several parameters

  Class binding France and France:

    Class binding method used to decorate @classmethod

    Special features: Regardless of class or object calls are automatically incoming class itself, as the first argument

  ps:

    When binding to the object: When the function logic requires access to data objects in time

    When binding to the class: When the data logic function needs to access the class when

   Non-binding method is not commonly used :()

    Called a static method that does not require data access objects

    Syntax: @staticmethod

 

 

Guess you like

Origin www.cnblogs.com/xiaowangba9494/p/11240787.html
Recommended