29.11.2014 Views

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

that no distinction is made between a class being <strong>an</strong> inst<strong>an</strong>ce of <strong>an</strong>other class<br />

inst<strong>an</strong>ce of the Dictionary class.<br />

<strong><strong>an</strong>d</strong> a user generated<br />

32.5.4 Class inherit<strong>an</strong>ce<br />

A point we have still not covered is what does the class Metaclass inherit from? Remember all<br />

classes (except <strong>Object</strong>) have a superclass <strong><strong>an</strong>d</strong> Metaclass is no exception. Metaclass inherits<br />

from ClassDescription, this is because the structure of classes <strong><strong>an</strong>d</strong> metaclasses are very similar.<br />

For example inst<strong>an</strong>ces of both Class <strong><strong>an</strong>d</strong> Metaclass c<strong>an</strong> have methods. In turn, the metaclass of<br />

Metaclass, (i.e. Metaclass class ) follows the st<strong><strong>an</strong>d</strong>ard laid d own <strong><strong>an</strong>d</strong> it inherits from the<br />

ClassDescription class. This is illustrated in Figure 32.7.<br />

As ClassDescription is a subclass of Behavior, it also me<strong>an</strong>s that both Class <strong><strong>an</strong>d</strong><br />

Metaclass inherit from the facilities provided b y Behavior. This me<strong>an</strong>s that inst<strong>an</strong>ces of both<br />

Metaclass <strong><strong>an</strong>d</strong> Class c<strong>an</strong> create new inst<strong>an</strong>ces etc. (Remember Behavior provides all the protocol for<br />

making new inst<strong>an</strong>ces so this is not surprising).<br />

Behaviour<br />

Behaviour<br />

class<br />

ClassDescription<br />

ClassDescription<br />

class<br />

Class<br />

Class class<br />

<strong>Object</strong><br />

<strong>Object</strong> class<br />

Collection<br />

Collection<br />

class<br />

Metaclass<br />

Metaclass<br />

class<br />

Set<br />

Set class<br />

Dictionary<br />

Dictionary<br />

class<br />

Figure 32.7: Class inherit<strong>an</strong>ce<br />

We are now left with the class Behavior <strong><strong>an</strong>d</strong> what it inherits from. All other classes have been<br />

accounted for. What then does Behavior inherit from? It inherits from the class <strong>Object</strong>. This closes<br />

the loop <strong><strong>an</strong>d</strong> ensures that all things in the whole of <strong>Smalltalk</strong> are objects (i.e. at some point their class<br />

inherits from <strong>Object</strong>) whether they are class, metaclasses or ordinary inst<strong>an</strong>ces.<br />

274

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!