正在加载图片...
730 HOW TO FIND THE CLASSES $22.2 what would have been a simple record(structure)type in Pascal,Ada or C.Not all record types cover separate data abstractions. You should investigate such a case carefully to try to understand whether there is room for a legitimate class,now or in the future.If the answer is unclear,you may be better off keeping the class anyway even if it risks being overkill.Having a class may imply some performance overhead if it means dealing with many small objects,dynamically created one by one and occupying more space than simple array elements;but if you do need a class and have not introduced it early enough,the adaptation may take some effort. We had such a false start in the history of ISE's compiler.A compiler for an O-O language needs some internal way to identify each class of a system it processes;the identification used to be an integer.This worked fine for several years,but at some point we needed a more elaborate class identification scheme,allowing us in particular to renumber classes when merging several systems.The solution was to introduce a class CLASS_IDENTIFIER,and to replace the earlier integers by instances of that class.The conversion effort was more than we would have liked,as usually happens when you have missed an important abstraction.Initially /NTEGER was a sufficient abstraction because no commands were applicable to class identifiers;the need for more advanced features, in particular renumbering commands,led to the recognition of a separate abstraction. Mixed abstractions Another sign of an imperfect design is a class whose features relate to more than one abstraction. In an early release of the NeXT library,the text class also provided full visual text editing capabilities.Users complained that the class,although useful,was too big.Large class size was the symptom;the true problem was the merging of two abstractions(character string, and interactively editable text);the solution was to separate the two abstractions,with a class NS AttributedString defining the basic string handling mechanism and various others, such as NSTextliew,taking care of the user interface aspects. Meilir Page-Jones uses the term connascence(defined in dictionaries as the property [Page-Jones 1995]. of being born and having grown together)to describe the relation that exists between two features when they are closely connected,based on a criterion of simultaneous change:a change to one will imply a change to the other.As he points out,you should minimize connascence across class libraries;but features that appear within a given class should all be related to the same clearly identified abstraction. This universal guideline deserves to be expressed as a methodological rule (presented in"positive"form although it follows a discussion of possible mistakes): Class Consistency principle All the features of a class must pertain to a single,well-identified abstraction. The ideal class This review of possible mistakes highlights,by contrast,what the ideal class will look like. Here are some of the typical properties:730 HOW TO FIND THE CLASSES §22.2 what would have been a simple record (structure) type in Pascal, Ada or C. Not all record types cover separate data abstractions. You should investigate such a case carefully to try to understand whether there is room for a legitimate class, now or in the future. If the answer is unclear, you may be better off keeping the class anyway even if it risks being overkill. Having a class may imply some performance overhead if it means dealing with many small objects, dynamically created one by one and occupying more space than simple array elements; but if you do need a class and have not introduced it early enough, the adaptation may take some effort. We had such a false start in the history of ISE’s compiler. A compiler for an O-O language needs some internal way to identify each class of a system it processes; the identification used to be an integer. This worked fine for several years, but at some point we needed a more elaborate class identification scheme, allowing us in particular to renumber classes when merging several systems. The solution was to introduce a class CLASS_IDENTIFIER, and to replace the earlier integers by instances of that class. The conversion effort was more than we would have liked, as usually happens when you have missed an important abstraction. Initially INTEGER was a sufficient abstraction because no commands were applicable to class identifiers; the need for more advanced features, in particular renumbering commands, led to the recognition of a separate abstraction. Mixed abstractions Another sign of an imperfect design is a class whose features relate to more than one abstraction. In an early release of the NeXT library, the text class also provided full visual text editing capabilities. Users complained that the class, although useful, was too big. Large class size was the symptom; the true problem was the merging of two abstractions (character string, and interactively editable text); the solution was to separate the two abstractions, with a class NSAttributedString defining the basic string handling mechanism and various others, such as NSTextView, taking care of the user interface aspects. Meilir Page-Jones uses the term connascence (defined in dictionaries as the property of being born and having grown together) to describe the relation that exists between two features when they are closely connected, based on a criterion of simultaneous change: a change to one will imply a change to the other. As he points out, you should minimize connascence across class libraries; but features that appear within a given class should all be related to the same clearly identified abstraction. This universal guideline deserves to be expressed as a methodological rule (presented in “positive” form although it follows a discussion of possible mistakes): The ideal class This review of possible mistakes highlights, by contrast, what the ideal class will look like. Here are some of the typical properties: Class Consistency principle All the features of a class must pertain to a single, well-identified abstraction. [Page-Jones 1995]
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有