Object-oriented programming related basic concepts

1. Programming Paradigms

Programming paradigm , programming paradigm, or programming paradigm, (paradigm means paradigm, paradigm, paradigm means pattern, method), is a type of typical programming style, and refers to a typical type of software engineering style (you can compare the methodology). Such as: functional programming, procedural programming, object-oriented programming, imperative programming, etc. are different programming paradigms.

Programming paradigms provide (and determine) the programmer's view of program execution. For example, in object-oriented programming, programmers think of a program as a sequence of interacting objects, while in functional programming a program is thought of as a sequence of stateless functional computations.

Just as different groups in software engineering will advocate different "methodologies", different programming languages ​​will advocate different "programming paradigms". Some languages ​​are designed for a particular paradigm (such as Smalltalk and Java support object-oriented programming, while Haskell and Scheme support functional programming), while others support multiple paradigms (such as Ruby, Common Lisp, Python, and Oz).

1.1 Process Oriented Programming

"Procedure Oriented" (Procedure Oriented) is a process-centric programming idea. "Procedure-oriented" can also be called "record-oriented" programming ideas, do not support rich "object-oriented" features (such as inheritance, polymorphism), and they do not allow mixing persistent state and domain logic.

  • Features: Analyze the steps required to solve the problem, and then use functions to implement these steps step by step, and call them one by one when using them.
  • Advantages: complex problems are streamlined and simplified (a complex problem is divided into small steps to achieve, and it will be very simple to implement small steps)
  • Disadvantage: poor scalability
  • Application scenarios: Process-oriented programming ideas are generally used in scenarios where functions rarely need to be changed once they are implemented . If you just write some simple scripts and do some one-time tasks, the process-oriented approach is excellent. , famous examples are the Linux kernel, git, and Apache HTTP Server. But if the tasks you are dealing with are complex and require constant iteration and maintenance, then object-oriented is the most convenient.

1.2 Object-Oriented Programming

"Object-oriented programming" (Object-oriented programming, abbreviation: OOP) is a programming paradigm and a method of program development. An object refers to an instance of a class. It takes the object as the basic unit of the program, and encapsulates the program and data in it to improve the reusability, flexibility and extensibility of the software.
Object-oriented programming can be seen as the idea of ​​including various independent objects that call each other in the program, which is just the opposite of traditional thinking: traditional programming advocates viewing the program as a collection of functions, or directly It is a series of instructions given to the computer. Every object in object-oriented programming should be able to receive data, process data, and communicate data to other objects, so they can all be thought of as a small "machine", an object.

  • Advantage: high scalability

  • Disadvantages: The complexity of programming is much higher than that of process-oriented. If you don't understand object-oriented and start immediately and design programs based on it, it is extremely prone to over-design problems, and using object-oriented in some scenarios with low scalability requirements will increase the difficulty of programming. For example, the shell script program for managing the Linux system is not suitable for object-oriented design, but process-oriented is more suitable.

  • Application scenarios: Object-oriented programming promotes the flexibility and maintainability of programs, and is widely used in large-scale project design . In addition, proponents claim that object-oriented programming is easier to learn than it used to be because it makes it easier for people to design and maintain programs, making programs easier to analyze, design, and understand.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325213485&siteId=291194637