Inheritance definedTopSome Mysteries of objectdraw, ExplainedDescribing similar things

Describing similar things

Before we answer these questions, we need to consider some new concepts and their use within Grace. Let's start by thinking about how we describe things in English. We often describe real world objects as being like something else but then describe what the difference is:

We'd like to be able to do similar things in Grace, and these are exactly the kinds of things we can do with the keyword inherits. The class we "inherit" is the class that we are like. The constants, variables, and methods that we define indicate how the new class differs from the one that we are extending.

We have done this all semester to create graphicApplications. For example, consider the header

def fallingLeaves: GraphicApplication = object {
  inherits graphicApplication.size(500,500)

from our falling leaves example. fallingLeaves is a graphicApplication. It has the same behaviors and properties as other graphicApplications, except for the things that we specify: 1) how it it draws the display and 2) how it responds to mouse clicks (creating a tree from which leaves fall).

Here, we call fallingLeaves the subobject and graphicApplication the superclass.


Inheritance definedTopSome Mysteries of objectdraw, ExplainedDescribing similar things