OpenMusic

Visual Programming | Computer-Assisted Composition

OpenMusic Reference

Prev| Chapter 9. Classes, Instances, and Factories| Next


Inheritance

Inheritance is a characteristic of classes in object-oriented programming languages. Take the example of two imaginary classes, publication and book. A publication would have slots like number of pages and editor . All books have a number of pages and apublished. But a book might also have a single author . Rather than redefining the number of pages and the the editor of the book anew, the class book could inherit from the class publication. book would include all of the slots of publication with an extra slot, author . Other kinds of publications ( pamphlet , magazine ) would also inherit from publication but have their own additional slots with information specific to them. Organizing classes into heirarchies of inheritance makes prorgams more logical and easier to write.

Inheritance can be put to work for you! OM music factory icons have the capacity to accept data directly from other classes via their self inputs. As an example, a Note’s self output can be plugged directly into the self input of Chord. A Chord is generated containing that note, because Chord knows what to do with Notes. Similarly, a list of Note objects is also acceptable at the self input of Chord.

You can find out what kinds of classes a given factory can accept at self from by using the online help in the patch window (accessed by selecting the object and hitting d.)

Note

Though passing a Note to a Chord is sort of like an example of inheritance, this is not really the case. Note does inherit, but from a class called simple-score- element (see below). When you pass self between factory objects, the factory is actually calling an internal method which translates the object.. Chord has methods for dealing with Chord (obviously) but also for dealing with Note and a list of Notes at its self input.

—|—


Prev Home Next
Factories and Instances Up Variables