正在加载图片...
24 CRITERIA FOR OBJECT ORIENTATION $2.2 Classes as modules Object orientation is primarily an architectural technique:its major effect is on the modular structure of software systems. The key role here is again played by classes.A class describes not just a type of objects but also a modular unit.In a pure object-oriented approach: Classes should be the only modules. In particular,there is no notion of main program,and subprograms do not exist as independent modular units.(They may only appear as part of classes.)There is also no need for the"packages"of languages such as Ada,although we may find it convenient for management purposes to group classes into administrative units,called clusters. Classes as types The notion of class is powerful enough to avoid the need for any other typing mechanism: Every type should be based on a class. Even basic types such as INTEGER and REAL can be derived from classes;normally such classes will be built-in rather than defined anew by each developer. Feature-based computation In object-oriented computation,there is only one basic computational mechanism:given a certain object,which (because of the previous rule)is always an instance of some class, call a feature of that class on that object.For example,to display a certain window on a screen,you call the feature display on an object representing the window-an instance of class WINDOW.Features may also have arguments:to increase the salary of an employee e by n dollars,effective at date d,you call the feature raise on e,with n and d as arguments. Just as we treat basic types as predefined classes,we may view basic operations (such as addition of numbers)as special,predefined cases of feature call,a very general mechanism for describing computations: Feature call should be the primary computational mechanism A class which contains a call to a feature of a class C is said to be a client of C. Feature call is also known as message passing;in this terminology,a call such as the above will be described as passing to e the message"raise your pay",with arguments d and .24 CRITERIA FOR OBJECT ORIENTATION §2.2 Classes as modules Object orientation is primarily an architectural technique: its major effect is on the modular structure of software systems. The key role here is again played by classes. A class describes not just a type of objects but also a modular unit. In a pure object-oriented approach: In particular, there is no notion of main program, and subprograms do not exist as independent modular units. (They may only appear as part of classes.) There is also no need for the “packages” of languages such as Ada, although we may find it convenient for management purposes to group classes into administrative units, called clusters. Classes as types The notion of class is powerful enough to avoid the need for any other typing mechanism: Even basic types such as INTEGER and REAL can be derived from classes; normally such classes will be built-in rather than defined anew by each developer. Feature-based computation In object-oriented computation, there is only one basic computational mechanism: given a certain object, which (because of the previous rule) is always an instance of some class, call a feature of that class on that object. For example, to display a certain window on a screen, you call the feature display on an object representing the window — an instance of class WINDOW. Features may also have arguments: to increase the salary of an employee e by n dollars, effective at date d, you call the feature raise on e, with n and d as arguments. Just as we treat basic types as predefined classes, we may view basic operations (such as addition of numbers) as special, predefined cases of feature call, a very general mechanism for describing computations: A class which contains a call to a feature of a class C is said to be a client of C. Feature call is also known as message passing; in this terminology, a call such as the above will be described as passing to e the message “raise your pay”, with arguments d and n. Classes should be the only modules. Every type should be based on a class. Feature call should be the primary computational mechanism
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有