Chapter10 - 10 Genericity From the merging of module and...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
10 Genericity F rom the merging of module and types concepts, we have been able to develop a powerful notion of class, which serves as the basis of the object-oriented method and can already, as it stands, enable us to do much. But to achieve our goals of extendibility, reusability and reliability we must make the class construct more flexible, an effort that will proceed in two directions. One, vertical in the figure below, represents abstraction and specialization; it will give rise to the study of inheritance in subsequent chapters. The present chapter studies the other dimension, horizontal in the figure: type parameterization, also known as genericity. 10.1 HORIZONTAL AND VERTICAL TYPE GENERALIZATION With the mechanisms studied so far we have all that we need to write the class at the center of the figure, LIST_OF_BOOKS , of which an instance represents a list of book objects. We know what kinds of feature it would have: put to add an element, remove to delete an Dimensions of generalization LIST_OF_ PEOPLE LIST_OF_ BOOKS LIST_OF_ JOURNALS SET_OF_ BOOKS LINKED_LIST_ OF_BOOKS Abstraction Specialization Type parameterization Type parameterization
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
GENERICITY § 10.2 318 element, count to find out how many elements are present and so on. But it is easy to see two ways of generalizing the notion of LIST_OF_BOOKS : Lists are a special case of “container” structure, of which other examples (among many) include trees, stacks and arrays. A more abstract variant might be described by a class SET_OF_BOOKS . A more specialized variant, covering a particular choice of list representation, might be described by a class LINKED_LIST_OF_ BOOKS . This is the vertical dimension of our figure — the dimension of inheritance. Lists of books are a special case of lists of objects of any particular kind, of which other examples (among many) include lists of journals, lists of people, lists of integers. This is the horizontal dimension of our figure — the dimension of genericity, our topic for the rest of this chapter. By giving classes parameters representing arbitrary types, we will avoid the need to write many quasi-identical classes — such as LIST_OF_BOOKS and LIST_OF_PEOPLE — without sacrificing the safety afforded by static typing. The relation between these two mechanisms is an elusive question for students of object-oriented concepts. Should inheritance and genericity be viewed as comrades or competitors in the rush towards more flexible software? That question is the subject of an appendix. In the present chapter we concentrate on genericity; this will also enable us to take a closer look at one of the most common examples of generic structure: arrays.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/02/2009 for the course CS 4376 taught by Professor Christeansan during the Spring '09 term at Dallas Colleges.

Page1 / 16

Chapter10 - 10 Genericity From the merging of module and...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online