正在加载图片...
18 Global objects and constants ocalknowledge is not always enouh components of a sofware system may need to access global information.It is easy to think of examples:a shared value,such as the size of available memory;an error window,to which all the components of an interactive system must be able to output messages;the gateway to a database or network In classical approaches,it is not difficult to provide for global objects;you just declare them as global variables,owned by the main program.In the modular style of design made possible by object-oriented techniques,there is neither a main program nor global variables.But even if our software texts do not include global variables our software executions may still need to share objects. Such global objects pose a challenge to the method.Object technology is all about decentralization,all about modularity,all about autonomy.It has developed from the beginning of this presentation as a war of independence for the modules,each fighting for its freedom from the excesses of central authority.In fact,there is no central authority any more.How then do we satisfy the need for common institutions?In other words,how do we allow components to share data in a simple way,without jeopardizing their autonomy, flexibility and reusability? It will not work,of course,to pass shared objects as arguments to the modules that need them.This would soon become clumsy if too many components need them.Besides, argument passing assumes that one module owns the value and then passes it on to others; in the case of a truly shared value no one module can claim ownership. To find a better answer we will start from a well-known notion,which we need in object-oriented software construction just as much as we did in more traditional approaches:constants.What is,after all,a constant such as Pi if not a simple object shared by many modules?Generalizing this notion to more complex objects will provide a first step towards fully general constant and shared objects. 18.1 CONSTANTS OF BASIC TYPES Let us start with a simple notation to denote constant values.18 Global objects and constants Local knowledge is not always enough; components of a software system may need to access global information. It is easy to think of examples: a shared value, such as the size of available memory; an error window, to which all the components of an interactive system must be able to output messages; the gateway to a database or network. In classical approaches, it is not difficult to provide for global objects; you just declare them as global variables, owned by the main program. In the modular style of design made possible by object-oriented techniques, there is neither a main program nor global variables. But even if our software texts do not include global variables our software executions may still need to share objects. Such global objects pose a challenge to the method. Object technology is all about decentralization, all about modularity, all about autonomy. It has developed from the beginning of this presentation as a war of independence for the modules, each fighting for its freedom from the excesses of central authority. In fact, there is no central authority any more. How then do we satisfy the need for common institutions? In other words, how do we allow components to share data in a simple way, without jeopardizing their autonomy, flexibility and reusability? It will not work, of course, to pass shared objects as arguments to the modules that need them. This would soon become clumsy if too many components need them. Besides, argument passing assumes that one module owns the value and then passes it on to others; in the case of a truly shared value no one module can claim ownership. To find a better answer we will start from a well-known notion, which we need in object-oriented software construction just as much as we did in more traditional approaches: constants. What is, after all, a constant such as Pi if not a simple object shared by many modules? Generalizing this notion to more complex objects will provide a first step towards fully general constant and shared objects. 18.1 CONSTANTS OF BASIC TYPES Let us start with a simple notation to denote constant values
向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有