Focus on solving problems with object-oriented thinking
When you encounter a requirement, you don't need to implement it yourself. If you implement it step by step, it is process-oriented; you should find someone who specializes in doing it.
Object-oriented (object-oriented; abbreviation: OO) There is no unified concept so far. We can define it as: according to people's systematic thinking way of understanding the objective world, using the concept of object (entity) to build a model, simulate the analysis of the objective world, Ways to design and implement software.
Object Oriented Programming (OOP) is a design and programming method to solve software reuse. This method describes the similar operating logic and operating application data and status in the software system in the form of classes, and reuses them in the software system in the form of object instances to achieve the effect of improving the efficiency of software development.
The concept of classes and objects
class
Class is a general term for a group of things with the same characteristics or behaviors. It is abstract and cannot be used directly;
Features are called attributes;
Behaviors are called methods.
Object
An object is a concrete existence created by a class and can be used directly;
An object created by which class has the properties and methods defined in that class;
The relationship between class and object
A class is a template for creating objects. There should be a class first and then an object;
A class can create multiple objects, and the properties of different objects may be different;
What methods are defined in the class, and what attributes and methods are there in the object. It is impossible to be less, but there may be more, because the object can add properties outside the class by itself
Define a simple class
Object-oriented is a larger encapsulation, encapsulating multiple methods in a class, so that objects created by this class can directly call these methods.
Define a class that only contains methods
Define a class that only contains methods in python Chinese medicine. The syntax format is as follows:
class class name:
def method 1(self,List parameter):
pass
def method 2(self,List parameter):
pass
The definition format of the method is almost the same as the function learned before;
The difference is that the first parameter must be self;
Note that the naming rules for class names must conform to the big hump naming method;
Create object
When a class is defined, use this class to create objects. The syntax is as follows:
Object variable=Class name()
The first object-oriented program
classCat:"""Define a cat"""
def eat(self):print("Kittens love to eat fish")
def drink(self):print("Kitten wants to drink water")
tom =Cat()
tom.eat()
tom.drink()
Knowledge point expansion:
The relationship between object-oriented design and object-oriented programming
Object-oriented design (OOD) does not specifically require object-oriented programming languages. In fact, OOD can be implemented by a purely structured language, such as C, but if you want to construct a data type with object properties and characteristics, you need to make more efforts in the program. When a language has built-in OO features, OO programming development will be more convenient and efficient. On the other hand, an object-oriented language does not necessarily force you to write OO programs. For example, C++ can be considered "better C"; while Java requires everything to be a class, and also stipulates that a source file corresponds to a class definition. However, in Python, neither classes nor OOP are necessary for everyday programming. Although it was designed from the beginning to be object-oriented and supports OOP structurally, Python does not limit or require you to write OO code in your application. OOP is a powerful tool, no matter you are preparing to enter, learn, transition, or turn to OOP, you can do everything at your disposal. One of the most important reasons to consider working with OOD is that it directly provides a way to model and solve real-world problems and situations.
So far, this article on what is object-oriented in python is introduced. For more related what is object-oriented content in python, please search for ZaLou.Cn's previous articles or continue to browse related articles below. Hope you will support ZaLou more in the future. .Cn!
Recommended Posts