您在這裡

Discussion

11 二月, 2015 - 12:05
In procedural programming, the programmer constructs procedures (or functions, as they are called in C++). The procedures are collections of programming statements that perform a specific task. The procedures each contain their own variables and commonly share variables with other procedures. Procedural programming is centered on the procedure or function. 1

For decades (1950s to through the 1980s) most programming was taught as procedural programming. Coupled with the imposition of using standardized control structures in the late 1960s, we have what is typically called modular structured programming.

Another, equally valid approach to programming is object-oriented programming or OOP. It was introduced in the mid 1980s and was widely accepted as a programming approach by the early 1990s. The first languages to introduce OOP to the masses were C++ and Java. Shortly after their introduction, there were American National Standards Institute (ANSI) standards established for those languages. Today, C++ and Java are widely used.

The primary diferences between the two approaches is their use of data. In a procedural program, the design centers around the rules or procedures for processing the data. The procedures, implemented as functions in C++, are the focus of the design. The data objects are passed to the functions as parameters. The key question is how the functions will transform the data they receive for either storage or further processing. Procedural programming has been the mainstay of computer science since its beginning and is still heavily used today.

In an object-oriented program, abbreviated OOP, the design centers around objects that contain (encapsulate) the data and the necessary functions to process the data. In OOP, the objects own the functions that process the data. 2
Object-oriented programming ... is centered on the object. An object is a programming element that contains data and the procedures that operate on the data. The objects contain, within themselves, both the information and the ability to manipulate the information. 3

To help complicate the picture, the C++ programming language can be used (and is used) to write either a procedural program (modular structured program) or an object-oriented program. Some items used by those writing procedural programs in C++ are in fact objects. Examples include:

  1. Standard input and output items of: cout and cin; example: cout.setf(ios::fixed)
  2. Strings; calculating the length with: identifier name.length()
  3. File input/output; example: inData.open (filespec, ios::in)

Objects are implemented with a "class" data type; which is a complex or derived data type. Implementation details will not be presented in the module.