正在加载图片...
$2.2 METHOD AND LANGUAGE 25 Information hiding When writing a class,you will sometimes have to include a feature which the class needs for internal purposes only:a feature that is part of the implementation of the class,but not of its interface.Others features of the class-possibly available to clients-may call the feature for their own needs;but it should not be possible for a client to call it directly. The mechanism which makes certain features unfit for clients'calls is called information hiding.As explained in a later chapter,it is essential to the smooth evolution of software systems. In practice,it is not enough for the information hiding mechanism to support exported features(available to all clients)and secret features (available to no client);class designers must also have the ability to export a feature selectively to a set of designated clients. It should be possible for the author of a class to specify that a feature is available to all clients,to no client,or to specified clients. An immediate consequence of this rule is that communication between classes should be strictly limited.In particular,a good object-oriented language should not offer any notion of global variable;classes will exchange information exclusively through feature calls,and through the inheritance mechanism. Exception handling Abnormal events may occur during the execution of a software system.In object-oriented computation,they often correspond to calls that cannot be executed properly,as a result of a hardware malfunction,of an unexpected impossibility (such as numerical overflow in an addition),or of a bug in the software. To produce reliable software,it is necessary to have the ability to recover from such situations.This is the purpose of an exception mechanism. The language should provide a mechanism to recover from unexpected abnormal situations. In the society of software systems,as you may have guessed,the exception mechanism is the third branch of government,the judicial system(and the supporting police force). Static typing When the execution of a software system causes the call of a certain feature on a certain object,how do we know that this object will be able to handle the call?(In message terminology:how do we know that the object can process the message?) To provide such a guarantee of correct execution,the language must be typed.This means that it enforces a few compatibility rules;in particular:§2.2 METHOD AND LANGUAGE 25 Information hiding When writing a class, you will sometimes have to include a feature which the class needs for internal purposes only: a feature that is part of the implementation of the class, but not of its interface. Others features of the class — possibly available to clients — may call the feature for their own needs; but it should not be possible for a client to call it directly. The mechanism which makes certain features unfit for clients’ calls is called information hiding. As explained in a later chapter, it is essential to the smooth evolution of software systems. In practice, it is not enough for the information hiding mechanism to support exported features (available to all clients) and secret features (available to no client); class designers must also have the ability to export a feature selectively to a set of designated clients. An immediate consequence of this rule is that communication between classes should be strictly limited. In particular, a good object-oriented language should not offer any notion of global variable; classes will exchange information exclusively through feature calls, and through the inheritance mechanism. Exception handling Abnormal events may occur during the execution of a software system. In object-oriented computation, they often correspond to calls that cannot be executed properly, as a result of a hardware malfunction, of an unexpected impossibility (such as numerical overflow in an addition), or of a bug in the software. To produce reliable software, it is necessary to have the ability to recover from such situations. This is the purpose of an exception mechanism. In the society of software systems, as you may have guessed, the exception mechanism is the third branch of government, the judicial system (and the supporting police force). Static typing When the execution of a software system causes the call of a certain feature on a certain object, how do we know that this object will be able to handle the call? (In message terminology: how do we know that the object can process the message?) To provide such a guarantee of correct execution, the language must be typed. This means that it enforces a few compatibility rules; in particular: It should be possible for the author of a class to specify that a feature is available to all clients, to no client, or to specified clients. The language should provide a mechanism to recover from unexpected abnormal situations
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有