正在加载图片...
166 THE STATIC STRUCTURE:CLASSES $7.2 Like an ADT,a class is a type:it describes a set of possible data structures,called the instances of the class.Abstract data types too have instances;the difference is that an instance of an ADT is a purely mathematical element(a member of some mathematical set),whereas an instance of a class is a data structure that may be represented in the memory of a computer and manipulated by a software system. For example if we have defined a class STACK by taking the ADT specification of the previous chapter and adding adequate representation information,the instances of that class will be data structures representing individual stacks.Another example,developed in the rest of this chapter,is a class PO/N7 modeling the notion of point in a two- dimensional space,under some appropriate representation;an instance of that class is a data structure representing a point.Under one of the representations studied below,the cartesian representation,each instance of POINT is a record with two fields representing the horizontal and vertical coordinates,x and y,of a point. The definition of"class"yields as a byproduct a definition of"object".An object is simply an instance of some class.For example an instance of class STACK-a data structure representing a particular stack-is an object;so is an instance of class PO/N7, representing a particular point in two-dimensional space. The software texts that serve to produce systems are classes.Objects are a run-time notion only:they are created and manipulated by the software during its execution. The present chapter is devoted to the basic mechanisms for writing software elements and combining them into systems;as a consequence,its focus is on classes.In the next chapter,we will explore the run-time structures generated by an object-oriented system;this will require us to study some implementation issues and to take a closer look at the nature of objects. 7.2 AVOIDING THE STANDARD CONFUSION A class is a model,and an object is an instance of such a model.This property is so obvious The next section,for that it would normally deserve no comments beyond the preceding definitions;but is has readers who do not been the victim of so much confusion in the more careless segment of the literature that like the belaboring of the obvious,is we must take some time to clarify the obvious.(If you feel that you are immune to such a “THE ROLE OF danger,and have avoided exposure to sloppy object-oriented teaching,you may wish to CLASSES”,7.3, skip this section altogether as it essentially belabors the obvious. page 169. What would you think of this? Among the countries in Europe we may identify the Italian.The Italian has a mountain chain running through him North-South and he likes good cooking,often using olive oil.His climate is of the Mediterranean type,and he speaks a beautifully musical language.166 THE STATIC STRUCTURE: CLASSES §7.2 Like an ADT, a class is a type: it describes a set of possible data structures, called the instances of the class. Abstract data types too have instances; the difference is that an instance of an ADT is a purely mathematical element (a member of some mathematical set), whereas an instance of a class is a data structure that may be represented in the memory of a computer and manipulated by a software system. For example if we have defined a class STACK by taking the ADT specification of the previous chapter and adding adequate representation information, the instances of that class will be data structures representing individual stacks. Another example, developed in the rest of this chapter, is a class POINT modeling the notion of point in a two￾dimensional space, under some appropriate representation; an instance of that class is a data structure representing a point. Under one of the representations studied below, the cartesian representation, each instance of POINT is a record with two fields representing the horizontal and vertical coordinates, x and y, of a point. The definition of “class” yields as a byproduct a definition of “object”. An object is simply an instance of some class. For example an instance of class STACK — a data structure representing a particular stack — is an object; so is an instance of class POINT, representing a particular point in two-dimensional space. The software texts that serve to produce systems are classes. Objects are a run-time notion only: they are created and manipulated by the software during its execution. The present chapter is devoted to the basic mechanisms for writing software elements and combining them into systems; as a consequence, its focus is on classes. In the next chapter, we will explore the run-time structures generated by an object-oriented system; this will require us to study some implementation issues and to take a closer look at the nature of objects. 7.2 AVOIDING THE STANDARD CONFUSION A class is a model, and an object is an instance of such a model. This property is so obvious that it would normally deserve no comments beyond the preceding definitions; but is has been the victim of so much confusion in the more careless segment of the literature that we must take some time to clarify the obvious. (If you feel that you are immune to such a danger, and have avoided exposure to sloppy object-oriented teaching, you may wish to skip this section altogether as it essentially belabors the obvious.) What would you think of this? Among the countries in Europe we may identify the Italian. The Italian has a mountain chain running through him North-South and he likes good cooking, often using olive oil. His climate is of the Mediterranean type, and he speaks a beautifully musical language. The next section, for readers who do not like the belaboring of the obvious, is “THE ROLE OF CLASSES”, 7.3, page 169
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有