Programming method
Source: Shangpin China |
Type: website encyclopedia |
Time: 2015-07-10
Website production A good program is like a movie. There is a big difference between a good one and a bad one. A good movie can make people want to see it after watching it, while a bad movie is seldom seen by people. A good program can not only solve problems, but also be easily understood, run efficiently, and easily modified. How to write a good program? This is a problem that programmers must consider before coding, that is, they need to select appropriate programming methods
With the continuous development of computer hardware technology, programming methods have also been developing. The earliest programming method is called individualized method. Every programmer writes programs according to his own habits and style, which results in difficult maintenance of programs. In particular, the individualized method of large-scale programs leads to the shortening of program life. The cost increases, which can not meet the needs. Through the efforts of computer workers and the continuous improvement of programming methods, in the past few decades, programming methods have mainly experienced two revolutionary leaps: structured methods and object-oriented methods. Correspondingly, process oriented programming and object-oriented programming have emerged. The following describes the structured method and the object oriented method
Structured programming, once known as the "revolution of programming methods", has turned programming from mainly relying on the free activities of programmers into a science with rules to follow. Its main contribution is to promote the change of programming style from "pursuing skills and efficiency" to "clarity first and efficiency second". Thus, the readability and reliability of the program are improved. In 1976, Professor Nikiaus Wirth of Switzerland pointed out in the preface of his classic classic "Algorithm 10 Data Structure 2 Program" that "a program is a specific description of an abstract algorithm based on the compilation of some specific representation forms and structures of data."; On the contrary, the structure and selection of algorithms are often based on the data structure. In short. Program composition and data structure are two inseparable problems. "
Worth's exposition. It brilliantly summarizes the position and relationship of algorithms and data structures in programming at that time "Algorithm+data structure two programs" has influenced and guided generations of programmers. From the early programming languages Fortran, Cobol, ADA, Pascal to the modern C language, they are all process oriented and have one feature: when analyzing or designing software, developers always follow the idea of "program two data structures and ten algorithms". They understand the program as a group of passive data and a group of active processes, Such programming method is called process oriented programming method.
The popularization of structured programming promoted the industrialization of software production, and also eased the software crisis at that time. However, its process oriented programming idea is not suitable for increasingly complex application systems. Practice shows that it is very effective to deal with software with less than 5000 lines of code with structured technology, but facing the complexity of today's large-scale software products. But still powerless. However, in objective things, the internal "state state" (represented by available data) and "motion" (operations added to data) of the entity are combined. This makes the software model (called "solution space" solution domain) developed using the traditional paradigm artificially deviate from the model of the objective entity itself (called "problem space", problem domain), Object oriented methods came into being.
In object-oriented programming, data and its operations are encapsulated in a unity called "Object", and objects are connected with each other through "Message". The mechanism of "Object+Message" replaces the idea of "Data Structure+Algorithm", Therefore, the consistency between "solution space" and "problem space" is well realized, which brings new hope for solving the software crisis. From structured programming to object-oriented programming is another leap of programming methods, and its advantages are increasingly revealed in software development and maintenance.
The idea of object-oriented originally originated from the simulation programming language Simula 67 in the mid-1960s. Smalltalk language appeared in the early 1980s and C++, Java language and its programming environment introduced in the 1990s have successively become important milestones in the development of object-oriented technology. Since the late 1980s, object-oriented programming and object-oriented demand analysis have developed rapidly. In particular, in the mid-1990s, lBooch, Rumbaugh and Jackson jointly put forward the Unified Modeling Language (CML), which integrates many object-oriented methods into a standard, making object-oriented methods become mainstream programming methods.
(1) Object is the abstract representation of an individual or thing in the real world, and is the unified encapsulation of its attributes and related operations. Attributes represent the properties of objects, and attribute values specify all possible states of objects. The operation of an object refers to the external services that the object can represent. For example. If the truck is considered an object. It has properties such as position, speed, color and capacity. The object can be started, stopped, accelerated, maintained, etc. These operations will more or less change the attribute value of the truck.
(2) Class. Classes are used to represent the common characteristics (properties and operations) of some objects, and objects are instances of classes. For example, the car class can include attributes such as position, speed, color, and operations such as starting, stopping, and accelerating. The truck is an instance of the car class.
(3) Inheritance classes can have inheritance relationships. It is a direct simulation of genetic relationships in the real world, and can be used to express the internal relationship between classes and share attributes and operations. A subclass can follow some characteristics of its parent class (the inherited class). At the same time, a subclass can also have its own unique properties and operations. Changes to a class can be automatically reflected in all its subclasses. For example, aircraft, cars and ships are all subclasses of the vehicle class, and they can all inherit some attributes and operations of the vehicle class. In addition to the inheritance relationship, there are also a lot of "part and whole" relationships in the real world. For example, an aircraft may be composed of an engine, a fuselage, a mechanical control system, an electronic control system, etc. This relationship can be expressed as an aggregation relationship between classes in object-oriented methodology. In an aggregation relationship, an object of the "part" class is a component of an object of the "whole" class.
(4) Message. Messaging is the only way for an object to correlate with its external world. An object can send a message to other objects to request services, or respond to messages from other objects to complete some of its own operations to serve other objects, for example. The helicopter can respond to the ship's emergency signal, take off, accelerate, fly to the accident site and carry out rescue operations. Object operations are mainly used to respond to foreign messages and provide services for other objects, so they are also called "external services". Coad and Yourdon think. The software system developed with the above four concepts can be regarded as object-oriented. To this end, they reduced the object-oriented method to a simple formula, that is, time image oriented two objects+classification+inheritance+communication with messages.
Source Statement: This article is original or edited by Shangpin China's editors. If it needs to be reproduced, please indicate that it is from Shangpin China. The above contents (including pictures and words) are from the Internet. If there is any infringement, please contact us in time (010-60259772).