Lecture
Classification is a means of ordering knowledge. In object-oriented analysis, determining the common properties of objects helps to find common key abstractions and mechanisms, which in turn leads us to a simpler architecture of the system. Unfortunately, no rigorous methods of classification have yet been developed, and there is no rule that allows classes and objects to be identified. There are no such things as "the perfect class structure" or "the right choice of objects". As in many engineering disciplines, the choice of classes is a compromise decision.
At one of the conferences programmers were asked the question: "What rules do you follow in defining classes and objects?" Stroustrup, the developer of the C++ language, answered: "It is like the quest for the Holy Grail. There is no panacea". Gabriel, one of the developers of CLOS, said: "This is a question to which there is no simple answer. I just try" . Fortunately, there is a wealth of experience of classification in other sciences, on the basis of which methods of object-oriented analysis have been developed. Each such method offers its own rules (heuristics) for identifying classes and objects. They will be the subject of this chapter.
4.1. The importance of proper classification
Classification and object-oriented design
Defining classes and objects is one of the hardest tasks of object-oriented design. Our experience shows that this work usually contains elements of discovery and invention. By means of discovery we recognize the key concepts and mechanisms that form the vocabulary of the problem domain. By means of invention we devise generalized concepts, as well as new mechanisms that determine the rules of interaction of objects. Discovery and invention are therefore inseparable parts of successful classification. The aim of classification is to find the common properties of objects. In classifying, we combine into a single group objects that have the same structure or the same behavior.

Classification is a means of ordering knowledge.
Sensible classification is undoubtedly part of any science. Michalski and Stepp assert: "an inherent task of science is the construction of a meaningful classification of observed objects or situations. Such a classification substantially facilitates the understanding of the basic problem and the further development of scientific theory" . The same philosophy applies to engineering as well. In the field of building architecture and town planning, as Alexander notes, for an architect "his design activity, both modest and gigantic in size, is governed entirely by the images he holds in his mind at the given moment, and by his ability to combine these images in creating a new design" .
It is not surprising that classification touches upon many aspects of object-oriented design. It helps to determine hierarchies of generalization, specialization and aggregation. Having found common forms of interaction of objects, we introduce mechanisms that will become the foundation for the implementation of our design. Classification helps to determine the module structure correctly. We may place objects in the same or in different modules, depending on the degree of similarity of the objects; coupling and cohesion are merely measures of this similarity.
Classification plays a large role in distributing processes among processors. We direct processes to one processor or to different ones depending on how these processes are connected with one another.
The difficulties of classification
Examples of classification. In chapter 3 we defined an object as something having crisp boundaries. In fact this is not entirely so. The boundaries of things are often indefinite. For example, look at your leg. Try to determine where the knee begins and ends. In colloquial speech it is difficult to understand why exactly these sounds define a word, rather than being part of some longer word. Imagine that you are designing a text editor. What should be considered a class - letters or words? How are individual phrases, sentences, paragraphs, documents to be understood? How should arbitrary, not necessarily meaningful, blocks of text be handled? What is to be done with sentences, paragraphs and whole documents - do such classes correspond to our problem?
That sensible classification is a difficult problem is no news. And since there are parallels with analogous difficulties in object-oriented design, let us consider examples of classification in two other scientific disciplines: biology and chemistry.
Right up to the eighteenth century the idea that living organisms could be classified by degree of complexity was the dominant one. The measure of complexity was subjective, so it is not surprising that man turned out to be first on the list. In the middle of the eighteenth century the Swedish botanist Carl Linnaeus proposed a more detailed taxonomy for classifying organisms: he introduced the notions of genus and species. A century later Darwin put forward the theory that the mechanism of evolution is natural selection and that the species of animals existing today are the product of the evolution of ancient organisms. Darwin's theory was based on a sensible classification of species. As Darwin asserts, "naturalists try to arrange the species, genera and families in each class into what is called the Natural System. But what is meant by this system? Some authors understand it as merely a simple scheme allowing the most alike living organisms to be placed in one class and the unlike in different classes" . In modern biology the term "classification" denotes "the establishment of a hierarchical system of categories on the basis of presumed natural relationships among organisms" . The most general concept in biological taxonomy is the kingdom, then, in order of decreasing generality: phylum (division), class, order, family, genus and, finally, species. Historically it has come about that the place of each organism in the hierarchical system is determined on the basis of the external and internal structure of the body and evolutionary relationships. In the modern classification of living beings, groups of organisms having a common genetic history are distinguished, that is, organisms having similar DNA are included in one group. Classification by DNA is useful for distinguishing organisms that look alike externally but differ greatly genetically. According to modern views, dolphins are closer to cows than to trout .
To a programmer, biology may perhaps appear to be a mature, fully formed science with definite criteria for classifying organisms. But this is not so. The biologist May said: "To this day we do not even know the order of magnitude of the number of species of plants and animals inhabiting our planet: fewer than 2 million species have been classified, while the possible number of species is estimated at from 5 to 50 million" . Moreover, different criteria for classifying the same animals lead to different results. Martin asserts that "it all depends on what you want to get. If you want the classification to speak of the blood kinship of species, you will get one answer; if you wish to reflect the level of adaptation, the answer will be different" . One may conclude that even in the exact scientific disciplines the methods and criteria of classification depend strongly on the purpose of the classification.
An analogous situation has developed in chemistry as well . In ancient times it was thought that all substances were combinations of earth, air, fire and water. At present such a classification cannot be considered in any way satisfactory. In the middle of the seventeenth century Robert Boyle proposed elements as the primitive chemical abstractions out of which more complex substances are composed. A century later, in 1789, Lavoisier published the first list containing 23 elements, although it was subsequently discovered that some of them were not elements at all. But the discovery of new elements continued, and the list grew. Finally, in 1869 Mendeleev proposed the periodic law, which gave exact criteria for classifying the known elements and could even predict the properties of elements not yet discovered. But even the periodic law was not the end of the story of the classification of elements. At the beginning of the twentieth century elements were discovered with identical chemical properties but with different atomic weights - isotopes.
The conclusion is simple. As Descartes asserted: "The discovery of an order is no easy task, but once the order has been discovered there is no difficulty at all in knowing it" [10]. The best programming solutions look simple, but, as experience shows, achieving a simple architecture is very difficult.
The iterative nature of classification. We have given all this information here not in order to justify "long-drawn-out construction" in software, although in fact it seems to many managers and users that centuries are needed to finish the work begun. We merely wanted to emphasize that sensible classification is intellectual work and that the best way of conducting it is a successive, iterative process. This becomes obvious when analyzing the development of such software products as the graphical interface, database standards and fourth-generation programming languages. Shaw asserts that in software development "the development of some abstraction often follows a general scheme. At first the problem is solved ad hoc, that is, somehow or other, for each particular case. As experience accumulates, some solutions turn out to be more successful than others, and a kind of folklore arises, passing from person to person. The successful solutions are studied more systematically, they are programmed and analyzed. This makes it possible to develop models, to carry out their automatic implementation, and to work out a theory generalizing the solution found. This in turn raises practice to a higher level and makes it possible to tackle a still more complex problem, which in its turn we approach ad hoc, thereby beginning a new turn of the spiral" [11].
The iterative approach to classification leaves a corresponding imprint on the procedure of constructing a hierarchy of classes and objects in the development of complex software. In practice, some definite class structure is usually taken as a basis and is then gradually improved.

Different observers classify one and the same object differently.
And only at a late stage of development, when some experience of using such a structure has already been gained, can we critically assess the quality of the resulting classification. On the basis of the experience gained we may create a new subclass from existing ones (derivation), or split a large class into many small ones (factorization), or, finally, merge several existing ones into one (composition). Possibly, in the course of development new common properties will be found that were not noticed earlier, and we shall be able to define new classes (abstraction) [12].
Why then is classification so difficult? We explain this by two reasons. First, by the absence of a "perfect" classification, although, naturally, some classifications are better than others. Coombs, Raiffa and Thrall assert that "there are as many ways of dividing the world into object systems as there are scientists who undertake this task" [13]. Any classification depends on the point of view of the subject. Flood and Carson give an example: "The United Kingdom... may be regarded by economists as an economic institution, by sociologists as a society, by environmentalists as a dying corner of nature, by American tourists as a sight, by Soviet leaders as a military threat, and finally, by the most romantic of us British as the green meadows of home" [14]. Second, sensible classification requires a fair share of creative insight. Birtwistle, Dahl, Myhrhaug and Nygaard conclude that "sometimes the answer is obvious, sometimes it is a matter of taste, and sometimes it all depends on the ability to notice what is essential" [15]. All this resembles the riddle: "Why is a laser beam like a goldfish?.. Because neither of them can whistle" [16]. One has to be a very creative thinker to find what is common in such unconnected things.
Comments