Note: This is just a job for object-oriented technology, just sticked, don't mind :)
Evolution from programming language and programming models Thinking object-oriented technology
Abstract Object-oriented programming and data abstraction plays a very important status in modern program design ideas, in which the relationship between the development of programming language and the evolution of programming ideas, understanding and thinking Object program design technology, and gradually discuss the following topics: the evolution of program design language, the evolution of program design ideas, the main ideas and concepts supported by object-oriented programming, and the final use of an array to illustrate the advantages of object-oriented programming .
The essence of computer programming is the problem we encountered in real life, through abstraction and then transforming the level to the machine to understand, and ultimately utilizing machines to seek problem. In this process, two aspects of problems are involved: 1. How to abstract the problem we face? Make problems can be described well abstract language. Second, how to map the problem that has been resolved to the machine to understand the language. From the first aspect, the second aspect is reflected in the second aspect of the programming language. It can be seen that the two are closely related, where the connection point is an abstract mechanism.
1. The introduction of programming language is an evolving process. The fundamental driving force is a higher demand for abstract mechanisms, as well as better support for programming ideas. Specifically, it is to improve the language that the machine can understand is also possible to imitate the form of human thinking. The evolution of programming language From the first machine language to assembly language to various structured advanced languages, and finally to support object-oriented language-oriented language, it is reflected is an abstract mechanism that has improved evolutionary roads, machine language and assembly language. Almost no abstraction, the most appropriate description for the machine, it can operate the unit in the machine, and any operation is for the machine, which requires people to follow the machine or assembly language. The machine's way to think about the problem, because there is no abstract mechanism, the programmer is easy to fall into a complex thing. With the birth of C, PASCAL, FORTRAN, etc., making programmers can leave the machine level, express the intent at a more abstract level. In particular, the three important control structures of this birth, and some basic data types can start thinking and squeene in the nature of proximity issues. As the scale of the program, the software crisis has appeared in the late 1960s, and the error cannot be overcome in the program design model in the time of the program, and the number-like expansion of the code is uncontrolled. At this time, there is a new thinking program design method and program model ----- object-oriented programming, thereby also born a batch of programming languages that support this technology, such as Eiffel, C , Java, These languages look at the problem with a new point of view, ie the problem is the message transfer between the objects of various different attributes and the objects between the objects. Object-oriented language thus must support new programming technology, such as data hidden, data abstraction, user-defined type, inheritance, polymorphism, etc.
2. Evolution of programming model
2.1 Process Program Design
The original programming model is:
What is the need to determine; the best algorithm that can be found.
Here is the process of processing ---- Algorithms required to perform expected calculations, from the viewpoint of program organization, the function is used to establish a order in many algorithms. The algorithm itself writes through function calls and other language functions, and its typical language is Pascal.
2.2 Module programming
The focus of the design program has been transferred from the relevant process to the organization of data, which also reflects the case where the program size is increased. The relevant process is organized with the data they operate, which is known as a module, and the program design is made: what modules are required; divide the program into some modules, so that the data is hidden in the module.
In such a design model, the most important concept is the principle of data hidden.
2.3 Object-based programming
Allow programmers to directly define types, such types of behavior are almost exactly the same, such types are often referred to as abstract data types, and their programming models are: What types of programs are required; provide a complete A set of operations.
A typical design language that supports this model is ADA.
2.4 Object-Oriented Program Design
Based on the object programming model, join inheritance and polymorphism These two groups of important concepts have evolved the most popular programming method --- object-oriented programming, the model is:
Determine which classes are needed; provide a complete set of operations for each class; use inheritance to express commonality.
Typical languages for this model are Eiffel, Java, C , etc. 3. The most basic concept / mechanism for object-oriented object-oriented object-oriented programming is an object, and an object can be defined by a software unit consisting of a method (data) and operation of this data. Data cannot be directly accessed by the user of the object, only allowing the data to be accessed by the object or code (that is, the function calls it).
The encapsulation object contains both data and method (code) that is operated or changing the data.
The object's service defines how other gaps are accessible to their methods. Each object will be willing to provide public service disclosure to all objects. It also provides only other services that are limited to specific objects (protection and private). I provide service ideas define the second principle of object-oriented models - information hide. Information Hide Object Definition What Service (Function) contains Object (Function), in fact, other objects cannot access or do not access or do data (attributes) and how to provide service (method / code).
The object can use the message mechanism to send a message of the prototype of the service by using the message mechanism, which can use the public service of another object. The message mechanism constitutes a third principle of object-oriented model-message delivery. The message delivery object can only communicate with other objects with a message delivery mechanism. Each message must send a specified recipient, and the interpretation of the message is from the recipient. In an object-oriented type, a specific recipient of a given message is usually known at runtime. Thus, there is a later connection between the message and the method used to complete the light ride of the behavior. The function call in the ordered program model is an early connection with the code snippet. The support for later connections defines the fourth principle of object-oriented models - back. Later connection it can determine a particular recipient to perform at runtime and its corresponding methods to be executed.
Not only will we organize objects as categories, but also organize the category to a special hierarchy. This introduces us the fourth principle of object-oriented. Unresential generalization can organize classes with hierarchical inheritance structures. In this mechanism, the subclass will inherit attributes, relationships, and methods from the parent class located on several structures, and abstract parent categories refer to supercles that are only used to generate subclasses. This abstract class has no direct instance. Polymorphisms can be organized using hierarchical inheritance structures, and the subclass can inherit the tree, relationships, and methods of the high-level parent class located in the tree structure. However, the subclass can produce its own way to replace any other superclass.
4, the evolution of the array
Arrays are the collection of the same type of elements, I will specifically explain the advantages of the object-oriented programming and the concepts supported by object-oriented programming. 4.1 Built-in array data type
// Declare an integer array int Fun [];
Although C provides built-in support to array types, this support is limited to "read and write individual elements". C does not support array abstraction, nor does it support operations of the entire array. For example: We cannot copy a array to another array, compare two arrays, or want to know the size of the array.
INT Array0 [10], Array1 [10]; // Error: You cannot copy a array directly to another array0 = array1; int fun [];
If we want to copy a array to another, you must write your own:
For (int index = 0; Index <10; index) array0 [index] = array1 [index];
However, the array has no self-awareness. It does not know its length, and such programming reflects the separation of data and algorithms that operates. Any function can access an array. The array is unprotected for functions. This is the feature of the process of process.
4.2 array class
Below I will use the C class mechanism to design an array abstraction 1. There is built-in self-consciousness in the implementation of the array class, first it knows your size. 2, array class supports replication, comparison, etc. between arrays. 3. You can query the maximum planting and minimum values in the array, as well as the required values. 4, can be sorted.
Class Array {public: BOOL Operator == (const array ") const; bool operator! = (const array&)
Array & Operator = (Const Array &);
INT size (); void sort (); int min (); int max (); int find (int value);
PRIVATE: // ......}
Keyword Private and Public Controlling Accesss Access, generally public members provide the interface of this class - that is, the collection of behavior of this class. Private members provide private implementation code - that is, store information. This type of public excuse and private code are separated by information hidden. This allows us to perform overall operations to the array, and the bundle of data and algorithms can be implemented.
4.3 Inherited array base class
Generally speaking, our implementation may be for specific users, not universality, that is, some users may not need to sort such functions at all, but we join, how we can support various users What is the requirements of our array class? Object-oriented programming methods provide us with such a capability, inheritance mechanism and polymorphism.
We can implement universal and common properties through base classes, and a variety of special requirements, we express more than base classes by inheritance and polymorphism.
4.4 small knot
Through an array evolution, we can clearly see the core idea of object-oriented programming: abstract data type, inheritance and polymorphism. We can also clearly feel the benefits and advantages of object-oriented programming for process programming.
Object-oriented programming is a professional idea of a new program design for overcoming the software crisis. Its core is to use class to express various concepts. Under the influence of this idea, a group of object-oriented program is born. Language, through various languages and programming modifications, we can clearly see various advantages for object-oriented programming technology, and the root cause of this advantage - overcome the data and algorithms in process programming and algorithm completely separated The drawbacks, and in this basis, a variety of new organizational programs and methods of expression concepts, and finally, I passed the evolution of an array: the built-in type - array - array-based class base class has been deeply portrayed. Process program design To object-oriented programming - data package, algorithm and data separation, mode transition in the description of the problem (described by algorithm), and so on. Reference: "C Program Design Language" Machinery Press Stroustrup "C Primer Chinese" China Electric Press Lippman
"Object-Oriented Software Constructure" Machinery Press Bertrand.meyer