What is object orientation?
Object-oriented programming is a computer programming architecture.
A basic principle of OOP is that computer programs are composed of a single unit or object that acts as a subroutine.
OOP achieves the three main goals of software engineering: reuse, flexibility, and extensibility.
OOP= Object + class + inheritance + polymorphic + message, where the core concepts are classes and objects.
Object-oriented program design method is to simulate human thinking as much as possible, making software development method and process as close as possible to the human to know the world, the method and process to solve the problem of reality, and even have to describe the problem of problem space and solution space as consistent as possible in the structure, the objective world entities in the abstraction of the problem domain object.
Object oriented programming takes object as the core, and the method considers that the program consists of a series of objects.
Classes are abstractions of the real world, including data representing static properties and operations on that data, and objects are instantiations of classes. Objects communicate with each other through messaging to simulate connections between different entities in the real world.
In object-oriented programming, the object is the basic module of the program.
Second, object-oriented characteristics
1. The encapsulation
Encapsulation refers to the assembly of the data in a computer system and all the operation languages related to the data (that is, the program code describing the attributes and behaviors of each object) into an organic entity, and the encapsulation of them into a “module”, that is, a class. Provides a good foundation for modularity of related components of software architecture.
2. The inheritance
Inheritance is another important feature in object-oriented technology, which mainly refers to the connection and distinction between two or more classes.
3. The polymorphism
From a macroscopic point of view, polymorphism refers to that in object-oriented technology, when multiple objects receive the same exact message at the same time, the actions are different and have a variety of forms. From a micro point of view, polymorphism refers to the fact that in a class of a group of objects, object-oriented technology can use the same call method to call the same function name, even though several functions with the same function name represent different functions.
Third, object-oriented advantages
1. The concept of data abstraction can change the internal implementation while keeping the external interface unchanged, thus reducing or even avoiding interference to the outside world;
2. The redundant code can be greatly reduced through inheritance, and the existing code can be easily extended, improve the coding efficiency, reduce the probability of error, reduce the difficulty of software maintenance;
3. Combined with object-oriented analysis and object-oriented design, allowing the object in the problem domain to be directly mapped to the program, reducing the conversion process of the intermediate link in the process of software development;
4. By identifying and dividing the objects, the software system can be divided into several relatively independent parts, which is easier to control the software complexity to a certain extent.
5. Object-centered design can help developers grasp problems from both static (attribute) and dynamic (method) aspects, so as to better implement the system;
6. Through the aggregation and union of objects, the internal structure and external function of objects can be expanded under the principle of ensuring encapsulation and abstraction, so as to achieve the upgrade of objects from low to high.
Fourth, object-oriented defects
1. Low operation efficiency.
Heavy loading of classes can sacrifice system performance and slow down performance. Although CPU speeds are increasing and memory capacity is increasing, this problem will become more and more severe as the system size increases.
2. The class library is huge.
Because class libraries are too large, programmers need a period of time to master them. From the point of view of popularization and promotion, class libraries should be reduced on the basis of ensuring their complete functions.
3. Class library reliability.
The larger the system is, there will be hidden problems that we can’t predict. The programmer cannot guarantee that every class in the class library is 100% correct in various environments. When the class used has problems, it will affect the follow-up work, and the programmer may overturn the original work.