正在加载图片...
646 GLOBAL OBJECTS AND CONSTANTS $18.3 keys associated with various commands.In such a case,the constants will still be grouped in a class(where else could they be?),but there will not be any instances of that class;it is simply used as parent for the classes that need to access the constants,as in class EDITOR CONSTANTS feature Insert:CHARACTER is'i Delete:CHARACTER is'd';--etc. end elass SOME CLASS FOR THE EDITOR inherit EDITOR CONSTANTS ..Other possible parents .. feature.… ..Routines of the class have access to the constants declared in EDITOR CONSTANTS... end A class such as EDITOR CONSTANTS is used only to host a group of related See"FACILITY constants,and its role as an "abstract data type implementation"(our working definition INHERITANCE". of the notion of class)is less obvious than in earlier examples.But it definitely serves a 24.9,page847. useful purpose.We will examine its theoretical justification in a later chapter. The scheme shown would not work without multiple inheritance,since SOME CLASS FOR THE ED/TOR may need other parents,either for access to other constants or for more standard uses of inheritance. 18.3 CONSTANTS OF CLASS TYPES Symbolic constants,allowing you to use identifiers to denote certain constant values,are not just use ful for predefined types such as /NTEGER;the need also arises for types that developers have defined,through classes.Here the solution is less obvious. Manifest constants are inappropriate for class types A typical example in which you may need to define a constant for a non-basic types is that of a class describing complex numbers: class COMPLEX creation make cartesian,make polar feature x,y:REAL --Real and imaginary parts646 GLOBAL OBJECTS AND CONSTANTS §18.3 keys associated with various commands. In such a case, the constants will still be grouped in a class (where else could they be?), but there will not be any instances of that class; it is simply used as parent for the classes that need to access the constants, as in class EDITOR_CONSTANTS feature Insert: CHARACTER is 'i' Delete: CHARACTER is 'd'; -- etc. … end class SOME_CLASS_FOR_THE_EDITOR inherit EDITOR_CONSTANTS … Other possible parents … feature … … Routines of the class have access to the constants declared in EDITOR_CONSTANTS … end A class such as EDITOR_CONSTANTS is used only to host a group of related constants, and its role as an “abstract data type implementation” (our working definition of the notion of class) is less obvious than in earlier examples. But it definitely serves a useful purpose. We will examine its theoretical justification in a later chapter. The scheme shown would not work without multiple inheritance, since SOME_ CLASS_FOR_THE_EDITOR may need other parents, either for access to other constants or for more standard uses of inheritance. 18.3 CONSTANTS OF CLASS TYPES Symbolic constants, allowing you to use identifiers to denote certain constant values, are not just useful for predefined types such as INTEGER; the need also arises for types that developers have defined, through classes. Here the solution is less obvious. Manifest constants are inappropriate for class types A typical example in which you may need to define a constant for a non-basic types is that of a class describing complex numbers: class COMPLEX creation make_cartesian, make_polar feature x, y: REAL -- Real and imaginary parts See “FACILITY INHERITANCE”, 24.9, page 847
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有