Welcome to stationmaster online Station master school Study Python knowledge , What this article studies is 《Python in object-oriented Related overview and explanation 》. The main contents of this paper are : What is object-oriented 、 What are the objects in object-oriented 、Python What are the classes in 、 object-oriented programming What are the characteristics of ?
object-oriented ( English is Object Oriented, Abbreviation for OO) Object oriented is a software development method , A way of programming . A design idea , from 20 century 60 The concept put forward in the s has developed into a relatively mature programming idea , And gradually become the mainstream technology in the current software development field .
Object oriented thinking has been involved in all aspects of software development . Such as , Object oriented analysis (OOA,Object Oriented Analysis), Object oriented design (OOD,Object Oriented Design)、 And what we often call object-oriented programming (OOP,Object Oriented Programming).
Object oriented is a way to understand and abstract the real world , It is the product of the development of computer programming technology to a certain stage .
Object oriented objects (Object), It usually refers to the real things in the objective world , Material object , Real image . Every object is unique , They all have their own rules and states of motion . Objects interact with each other . in addition , An object can also be an abstract thing .
Usually , We divide the object into two parts : The static part and the dynamic part . The static part is called “ attribute ”, Any object has its own properties , It's objective , Such as human gender, height, fat, thin and other attributes ; The dynamic part refers to the behavior of the object , Such as human walking , having dinner , Sleep and other executable actions .
stay Python in , Everything is an object . Not only concrete things are objects , character string , function , list , Tuples , Dictionaries , aggregate Wait is the object , That explains it Python It's natural to be object-oriented .
object-oriented programming Is in Process oriented programming Developed on the basis of , It is more flexible and extensible than process oriented programming . To go further on the road of programming , Must deeply master the object-oriented programming technology .
stay Python in , Class is encapsulation Object attribute and behavior carrier . It can also be said that , A class of entities with the same properties and behavior is called a class .
Such as , Compare people to human beings , Then man has a head , neck , trunk , Limbs and other attributes , having dinner , sleep , Walk , Code words and other behaviors , And one who is coding The programmer Regarded as an object of human beings , The schematic diagram of the relationship between human beings and human objects is as follows :
Object - oriented programming has three main characteristics , Namely : encapsulation 、 Inherit and polymorphic .
Encapsulation is the core idea of object-oriented programming , Encapsulate the properties and behaviors of an object , The carrier that encapsulates the properties and behaviors of objects is the class . Encapsulation is to hide the properties and implementation details of objects , Only public interfaces , Control the access level of property reading and modification in the program , Abstract obtain Data and behavior ( Or function ) Combination , Form an organic whole , That is, the source of data and operation data Code Organic combination , formation “ class ”, Where data and functions are members of the class .
Take the car for example , People just operate the throttle 、 brake 、 Several parts such as the steering wheel can drive away , Without knowing how the car works inside .
Inheritance is one of the basic characteristics of object-oriented , The inheritance mechanism allows the creation of hierarchical classes .
Inheritance is implementation duplication Compound interest An important means used , Subclasses inherit the properties and behaviors of the parent class while , Added subclass specific attributes and behaviors .
stay Python in , Instances of subclasses are instances of parent classes , However, it cannot be said that an instance of a parent class is an instance of a child class . We can say that Shenzhen people are Cantonese , But we can't say that Cantonese are Shenzhen people .
stay Python in , Applying a parent object to a subclass feature is polymorphic . A child class inherits the characteristics of its parent class , It also has its own characteristics , Achieve different effects , This is polymorphism .
Polymorphism the same behavior has many different manifestations , That is, a class instance ( object ) The same method has different forms in different situations .
Only this and nothing more , this paper 《python Detailed description of object-oriented in 》 What is object-oriented 、 What are the objects in object-oriented 、Python What are the classes in 、 What are the characteristics of object-oriented programming , If you have questions, you can leave a message .