1. What is object orientation


ObjectOriented development method (OO) is also called rapid prototyping method.

The objective world is composed of a variety of objects, each object has its own internal state and movement rules, the interaction and connection between different objects constitute a variety of different systems. In the design and implementation of an objective system, the system is designed as a minimum set of immutable (relatively fixed) parts under the conditions of satisfying requirements (best design). These immutable parts are called objects.

###2. Composition of object-oriented development methods


1, object-oriented (requirements) analysis OOA

2. Object oriented design OOD

3, object-oriented program OOP

###3. The development process of object-oriented development method


1, system investigation and demand analysis: the system will face specific management problems and users of the system development needs to investigate, that is, to find out what to do first.

2, analyze the nature of the problem and solve the problem: in the complex problem domain abstractly identify the object and its behavior, structure, attribute, method, etc. This is commonly referred to as object-oriented analysis, or OOA.

3. Sorting out problems: Further abstract, categorize and sort out the results of the analysis, and finally determine them in the form of a paradigm. This is commonly referred to as object oriented design, or OOD.

4, program implementation: with object-oriented programming language will be the last step to organize the paradigm directly map (that is, directly replaced by programming language) for application software. It is commonly referred to as object-oriented programs, that is, OOP.

5. Identify objects and behaviors in the objective world and independently design entities of each object; Analyze the relationship between objects and the information transmitted by each other, thus forming the model of information system; Transform the information system model into the software system model, merge and organize each object, and determine the relationship between them; Transformation from software system model to target system.

###4. Basic concepts of object orientation


  • object

The object is anything to be studied. From a book to a library, vast databases of single integer to integer columns, extremely complex automated factories, and the Space shuttle can all be regarded as objects representing not only tangible entities but intangible (abstract) rules, plans, or events. An object is made up of data (describing properties of things) and operations that act on the data (representing behavior of things). From the programmer’s point of view, an object is a program module; from the user’s point of view, an object provides desired behavior. Operations inside are often called methods. An object requests service from another object by sending a message.

  • class

A class is a template for an object. That is, a class is a definition of a group of objects that have the same data and the same operations. The methods and data contained in a class describe the common behavior and properties of a group of objects. A class is an abstraction over an object, and an object is a materialization of a class, an instance of a class. A class may have subclasses or other classes, forming a class hierarchy.

  • The message

A message is a specification for communication between objects. It generally consists of three parts: the object receiving the message, the message name, and the actual argument.

  • inheritance

Inheritance means that, in some cases, a class has “subclasses.” Subclasses are more specific than the original class (called a parent class). For example, the “dog” class might have subclasses of “sheepdog” and “Chihuahua.” In this case, Les could be an example of a sheepdog. Subclasses inherit the attributes and behavior of their parent class, and may also contain their own. Let’s assume that the “dog” class has a method (behavior) called “bark ()” and a property called “fur color.” Its subclasses (the sheepdog and Chihuahua from the previous example) inherit these members. This means that programmers only need to write the same code once. In pseudocode we can write: Collie like: Inherited dog definition Les is collie Les. Bark () /* Notice that the bark method of the dog class is called. Returning to the previous example, the collie class can inherit the “fur color” attribute and specify brown and white. A Chihuahua, on the other hand, can inherit the bark and specify a higher-than-usual pitch. Subclasses can also add new members, for example, the “Chihuahua” class can add a method called “shiver ()”. If an instance of “Les” is defined using the “shepherd dog” class, les will not tremble because this method is for chihuahuas, not sheepdogs. In fact, we can think of inheritance as being or belonging. Les is a sheepdog, and sheepdogs are dogs. So Les got her collie and her dog. Let’s look at the pseudocode: Chihuahua-like: Inherited dog Start Public member: Tremble () End Class Sheepdog: Inherited dog definition Les is the sheepdog Les. Tremble ()/Error: Tremble is a chihuahua member method. */ When a class inherits from more than one parent class, we call it “multiple inheritance”. Like a dog that is both a Chihuahua and a shepherd (though it doesn’t really make sense). Multiple inheritance is not always supported because it is hard to understand and hard to use well.

  • encapsulation

Object-oriented programming with Encapsulation hides the specific execution steps of a method and instead sends messages to it through a messaging mechanism. So, for example, the “dog” class has the “bark ()” method, which defines exactly how the dog should bark. But Les’s friends didn’t know exactly how he barked. For example: /* A process-oriented program would say: / Define Les les. Set the tone (5) Les. Inhaling () Les. Exhaling ()/ While a dog’s bark is encapsulated in a class, anyone can simply use: */ Define Les as dog Les. Bark () encapsulation is done by restricting access to members of a particular class to objects that typically use interfaces to implement incoming and outgoing messages. For example, the interface ensures that attributes like puppies can only be assigned to dogs. Generally, members are divided into three categories based on their access rights: public members, private members, and protected members. Some languages go further: Java can restrict access to different classes within the same package; C# and VB.NET retain the keywords for aggregation of members of classes: internal (C#) and Friend (VB.NET); Eiffel lets users specify which classes have access to all members. [1]

  • polymorphism

A Polymorphism is the generation by inheritance of different, related classes whose objects respond differently to the same message. For example, dogs and chickens both have the bark () method, but if you call the dog’s bark (), the dog will bark; Call the “crow” of a chicken and the chicken will crow. End definition Les is the dog definition Ruth is the chicken Les. Call () Rust. Call () thus, although the same behavior is called, but the specific performance of Rice and Rust will be very different. The concept of polymorphism can be applied to operator overloading and is not covered in this article.

  • abstract

Abstraction is a way to simplify complex real-world problems by finding the most appropriate class definition for a specific problem and explaining the problem at the most appropriate inheritance level. For example, Les is treated like a dog most of the time, but if you want her to do what a sheepdog does, you can always use sheepdog methods. If the dog class had an animal parent, then you might as well consider Les an animal.

###5. Characteristics of object-oriented development


  • Encapsulation. In the object-oriented method, the program and data are encapsulated together, the object as an entity, its operation hidden in the method, its state is described by the object “attribute”, and can only be changed by the object “method”, from the outside world. Encapsulation forms the basis of the object-oriented approach. Thus, Codd and YOuMn, the founders of this approach, believe that object orientation is “object + attribute + method”.

  • Abstract. In the object-oriented method, the concept of the essential characteristics of things abstracted from entities with common properties is called “Class” (Class), and the object is an instance of the Class. Class encapsulates the common attributes and methods of objects. Objects created by instantiating a class automatically have the attributes and methods specified in the class.

  • Inheritance. Inheritance is a class-specific property. A class can be subclassed, which automatically inherits the attributes and methods of its parent class. In this way, when defining a subclass, you can greatly improve the reusability of your software by stating only the characteristics that make it different from its parent class.

  • Polymorphism. Polymorphism means that the same method of a class instance has different manifestations in different situations. The polymorphism mechanism enables objects with different internal structures to share the same external interface. This means that although the specific operations on different objects are different, they (those operations) can be invoked in the same way through a common class.

###6. Five basic principles of Object Orientation


  • The Single Responsibility Principle (SRP) means that the functions of a class should be Single and not all-inclusive. Just like a person, you should not assign too much work, otherwise you will be busy all day long, but you will not be efficient.

  • OCP(open-close Principle) A module should be Open in extensibility and closed in modification. For example: a network module, originally only server function, but now to add the client function, then should not modify the server function code premise, can add the client function code, which requires at the beginning of the design, should be separated from the server and client, the public part of the abstract out.

  • Subclasses should be able to replace the superclass and appear wherever the superclass can. For example, in the company’s annual party, all employees can participate in the lottery, so no matter the old employees or new employees, and no matter the headquarters employees or expatriate employees, they should be able to participate in the lottery, otherwise the company will not be harmonious.

  • The Dependency Inversion Principle DIP The Dependency Inversion Principle DIP Suppose B is A lower module than A, but B needs to use the functions of A. In this case, B should not directly use the concrete classes in A: Instead, B should define an abstract interface and LET A implement this abstract interface, and B only uses this abstract interface: In this way, the purpose of dependency inversion is achieved, and B is relieved of its dependence on A, which in turn depends on the abstract interface defined by B. It is difficult to avoid dependencies on lower-level modules through upper-level modules, and cyclic dependencies may result if B also relies directly on the implementation of A. A common problem is that modules A need to include CPP files directly into modules B, and modules B need to include CPP files directly into MODULES A.

  • The Interface Segregation Principle ISP modules are segregated by abstract interfaces rather than strongly coupled by concrete classes

###7. Why need an object-oriented approach


(1) Object-oriented approach is closer to the natural thinking of human beings. Three construction rules commonly used in human cognition and understanding of the real world are to distinguish objects and their attributes, to distinguish whole objects and their components, and to distinguish and form different object classes. Object orientation is based on the concepts of objects and attributes, categories and members, wholes and parts. Therefore, it must be easier to understand and use.

(2) System analysis, system design and implementation use the same perspective to view the problem and even the same representation method to describe the problem, the connection between them is natural seamless connection.

(3) Object-oriented approach to the object attributes and services as a whole.

This is more consistent with the laws of the objective world, thus making it easier to understand and implement, further reducing the cost of maintenance.

(4) Inheritance method on the one hand conforms to the law of the objective world, on the other hand strengthens the possibility of code reuse, so as to improve the efficiency of software development.

(5) The principle of information concealment makes the system have good adaptability in the changing environment, thus making the whole system more stable and easy to maintain.

In short, object-oriented approaches make it easier for people to understand and map the real world, and improve software development efficiency, reliability, and maintainability.

###8. The difference between procedural and object oriented


I saw an answer on Zhihu, which is very incisive

When a program performs a task, it tells a story. Process oriented is a chronicle. Object oriented is a chronicle. It turns out that object oriented is a better way to tell complex programs/big stories.

Chronicle: According to the chronology of history: according to the character of the clues