正在加载图片...
650 GLOBAL OBJECTS AND CONSTANTS $18.4 Once functions returning results of basic types Another application of once functions is to represent global values-"system parameters"-used by several classes in a system.Such values will usually be constant over a given system execution;they are initially computed from user input,or from some information obtained from the environment.For example: The components of a low-level system may need to know the available memory space,obtained from the environment at initialization time. A terminal handler may start by querying the environment about the number of terminal ports:once obtained,these data elements are then used by several modules of the application. Such global values are similar to shared objects such as Message window;but in general they are values of basic types rather than class instances.You may represent them through once functions.The scheme is: Const value:Tis --A system parameter computed only once local envir param:T Any type (T or another) once "Get the value of envir param from the environment" Result:="Some value computed from envir param" end Such once functions of basic types describe dynamically computed constants. Assume the above declaration is in a class ENVIR.A class needing to use Const value See"Modular will get it simply by listing ENVIR among its parents.There is no need here for an decomposability". initialization routine as might be used in classical approaches to compute Const value, page 40. along with all other global parameters,at the beginning of system execution.As was seen in an earlier chapter,such a routine would have to access the internal details of many other modules,and hence would violate the criteria and principles of modularity: decomposability,few interfaces,information hiding etc.In contrast,classes such as ENIIR may be designed as coherent modules,each describing a set of logically related global values.The first component that requests the value of a global parameter such as Const value at execution time will trigger its computation from the environment. Although Const value is a function,components that use it may treat it as if it were a constant attribute. The introduction to this chapter mentioned that none of the modules that use a shared value has more claim to own it than any of the others.This is especially true in the cases just seen:if,depending on the order of events in each execution of the system,any one among a set of modules may trigger the computation of the value,it would be improper to designate any single one among them as the owner.The modular structure reflects this.650 GLOBAL OBJECTS AND CONSTANTS §18.4 Once functions returning results of basic types Another application of once functions is to represent global values — “system parameters” — used by several classes in a system. Such values will usually be constant over a given system execution; they are initially computed from user input, or from some information obtained from the environment. For example: • The components of a low-level system may need to know the available memory space, obtained from the environment at initialization time. • A terminal handler may start by querying the environment about the number of terminal ports: once obtained, these data elements are then used by several modules of the application. Such global values are similar to shared objects such as Message_window; but in general they are values of basic types rather than class instances. You may represent them through once functions. The scheme is: Const_value: T is -- A system parameter computed only once local envir_param: T ' -- Any type (T or another) once “Get the value of envir_param from the environment” Result := “Some value computed from envir_param” end Such once functions of basic types describe dynamically computed constants. Assume the above declaration is in a class ENVIR. A class needing to use Const_value will get it simply by listing ENVIR among its parents. There is no need here for an initialization routine as might be used in classical approaches to compute Const_value, along with all other global parameters, at the beginning of system execution. As was seen in an earlier chapter, such a routine would have to access the internal details of many other modules, and hence would violate the criteria and principles of modularity: decomposability, few interfaces, information hiding etc. In contrast, classes such as ENVIR may be designed as coherent modules, each describing a set of logically related global values. The first component that requests the value of a global parameter such as Const_value at execution time will trigger its computation from the environment. Although Const_value is a function, components that use it may treat it as if it were a constant attribute. The introduction to this chapter mentioned that none of the modules that use a shared value has more claim to own it than any of the others. This is especially true in the cases just seen: if, depending on the order of events in each execution of the system, any one among a set of modules may trigger the computation of the value, it would be improper to designate any single one among them as the owner. The modular structure reflects this. See “Modular decomposability”, page 40
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有