Object-oriented programming (OOP)
program = instruction + data
Two types of paradigms
Process oriented:
Command-centric: writing around "What's going On"
The program has a series of linear steps; The main idea is that code is used for data
Object-oriented:
Data-centric: Writing around "Who's going to be affected"
Organize programs around data and interfaces that are strictly defined for data, and control access to code with data
The ultimate goal of all programming languages is to provide an abstract approach
Between the machine model ("solution space" or "solution space") and the Problem model ("problem space") that is actually solved, the programmer must establish a connection
Process oriented: program = algorithm + data structure
Object-oriented: Abstracts elements in the problem space and their representations in the solution space into objects and allows problems to be described rather than scenarios
You can think of an object instance as a new variable that is saved in a few, but can perform operations on its own data, such as:
Types are composed of state collections (data) and the set of operations that transform these states
Class Abstraction
Class: Defines the structure and behavior (data and code) that are shared by multiple objects of the same type
Note: The class itself cannot operate directly on itself, only after the instantiated class.
class data and code: a member of a class
Data: member variable or instance variable
Member methods: The abbreviation method, which is the code that operates the data, defines how member variables are used, so that the behavior and interface of a class are defined by methods
Object methods are actually provided by the class
Methods and variables:
Private: Internal Use
Public: Externally visible
Object-oriented Program design method
Everything can be understood as an object.
A program is a combination of a whole bunch of objects
By message passing, each object knows what to do
Message: Called the request, which invokes a method that is subordinate to the target object
A method call to an object can be interpreted as a call to a message, if the method interface exists to make the call, or an error is made
Each object has its own storage space and can hold the object
By encapsulating existing objects, they can be made into new objects
Each object belongs to a type
Type, that is, class
Object is an instance of a class
An important feature of the class is "what message can be sent to it"
Once a class is defined, you can instantiate multiple objects as needed
Each object can only accept a specific request
A request that can be sent to an object is defined by its "interface"
Inter-class relationships
For example:
The list depends on the string, and also on the number
Li = ["AAA", "BBBB"]
L1 = [1,3,4,78]
Python Learning the third day (object-oriented programming) 01