正在加载图片...
$34.2 OBJECT-ORIENTED PROGRAMMING IN PASCAL? 1101 Pascal proper How much of the object-oriented approach can you implement in Pascal? Not much.The Pascal program structure is based on a completely different paradigm.A Pascal program consists of a sequence of paragraphs,appearing in an immutable order:labels,constants,types,variables,routines (procedures and functions), and executable instructions.The routines themselves have the same structure,recursively. This simple rule facilitates one-pass compilation.But it dooms any attempt at using O-O techniques.Consider what it takes to implement an ADT,such as the standard example of stacks represented by arrays:a few constants such as the array size,one or a few types such as the record type describing the stack implementation,a few variables such as the pointer to the stack top,and a few routines representing the operations on the abstract data type.In Pascal,these elements will be scattered all over the program:all the constants for various abstract data types together,all the types together and so on. “Linguistic Modular The resulting program structure is the opposite of O-O designs.Using Pascal would Ums”page53. contradict the Linguistic Modular Units principle,which expresses that any modular policy you choose must be supported by the available language constructs,for fear of damaging composability,decomposability and other modularity requirements. So if we take Pascal as defined by its official standard,there is little we can do to apply O-O techniques this language beyond what was called the disciplinary approach above:imposing a strict methodological rule for data accesses. Modular extensions of Pascal Beyond standard Pascal,many commercially available versions remove the restrictions on the order of declarations and include support for some form of module beyond the routine, including separate compilation.Such modules may contain more than one routine, together with associated constants,types and routines.The resulting languages and products,more flexible and powerful than Pascal,are Pascal only by name;they are not standardized,and in fact resemble more an encapsulation language such as Modula-2 or Ada,to which the applicable discussion is that of the preceding chapter. Object-oriented extensions of Pascal Over the years a number of companies have offered object-oriented extensions of Pascal, loosely known as"Object Pascal".Two are particularly significant: Apple's version,originating from a language originally called Clascal and used for some of the software in Apple's Macintosh and its Lisa predecessor. Borland's version of Pascal,most recently adapted as the programming language for Borland's Delphi environment. The preceding discussion does not really apply to such languages since-even more than with the modular extensions-their connection to the original Pascal is essentially their name,syntactic style,and statically typed approach.Borland Pascal,in particular,is an O-O language with exception handling.It does not,however,support any of the mechanisms of genericity,assertions,garbage collection and multiple inheritance.§34.2 OBJECT-ORIENTED PROGRAMMING IN PASCAL? 1101 Pascal proper How much of the object-oriented approach can you implement in Pascal? Not much. The Pascal program structure is based on a completely different paradigm. A Pascal program consists of a sequence of paragraphs, appearing in an immutable order: labels, constants, types, variables, routines (procedures and functions), and executable instructions. The routines themselves have the same structure, recursively. This simple rule facilitates one-pass compilation. But it dooms any attempt at using O-O techniques. Consider what it takes to implement an ADT, such as the standard example of stacks represented by arrays: a few constants such as the array size, one or a few types such as the record type describing the stack implementation, a few variables such as the pointer to the stack top, and a few routines representing the operations on the abstract data type. In Pascal, these elements will be scattered all over the program: all the constants for various abstract data types together, all the types together and so on. The resulting program structure is the opposite of O-O designs. Using Pascal would contradict the Linguistic Modular Units principle, which expresses that any modular policy you choose must be supported by the available language constructs, for fear of damaging composability, decomposability and other modularity requirements. So if we take Pascal as defined by its official standard, there is little we can do to apply O-O techniques this language beyond what was called the disciplinary approach above: imposing a strict methodological rule for data accesses. Modular extensions of Pascal Beyond standard Pascal, many commercially available versions remove the restrictions on the order of declarations and include support for some form of module beyond the routine, including separate compilation. Such modules may contain more than one routine, together with associated constants, types and routines. The resulting languages and products, more flexible and powerful than Pascal, are Pascal only by name; they are not standardized, and in fact resemble more an encapsulation language such as Modula-2 or Ada, to which the applicable discussion is that of the preceding chapter. Object-oriented extensions of Pascal Over the years a number of companies have offered object-oriented extensions of Pascal, loosely known as “Object Pascal”. Two are particularly significant: • Apple’s version, originating from a language originally called Clascal and used for some of the software in Apple’s Macintosh and its Lisa predecessor. • Borland’s version of Pascal, most recently adapted as the programming language for Borland’s Delphi environment. The preceding discussion does not really apply to such languages since — even more than with the modular extensions — their connection to the original Pascal is essentially their name, syntactic style, and statically typed approach. Borland Pascal, in particular, is an O-O language with exception handling. It does not, however, support any of the mechanisms of genericity, assertions, garbage collection and multiple inheritance. “Linguistic Modular Units”, page 53
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有