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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ehavior, but from the point of view of th e metaclass, all classes are constructed in the same way, are<br />

structured in the same way (i.e. they have class methods, class inst<strong>an</strong>ce variables <strong><strong>an</strong>d</strong> class variables)<br />

<strong><strong>an</strong>d</strong> all require the same set of operations (i.e. they must be able to construct inst<strong>an</strong>ces).<br />

32.5.2 What is metaclass <strong>an</strong> inst<strong>an</strong>ce of?<br />

Metaclass class<br />

(metaclass)<br />

Metaclass<br />

Array class<br />

(metaclass)<br />

Array<br />

#(1 2 3 4) #($a $b $c)<br />

Figure 32.5: Inst<strong>an</strong>ce relationships between inst<strong>an</strong>ces, classes <strong><strong>an</strong>d</strong> metaclasses for array<br />

Metaclass, being a class, must also be <strong>an</strong> inst<strong>an</strong>ce of somet hing. Following the st<strong><strong>an</strong>d</strong>ards laid down<br />

about it is therefore <strong>an</strong> inst<strong>an</strong>ce of its metaclass. This metaclass, like all other metaclasses, has its name<br />

derived from the class, it is therefore called Metaclass class . However, every metaclass is <strong>an</strong><br />

inst<strong>an</strong>ce of Metaclass, thus the Metaclass class is <strong>an</strong> inst<strong>an</strong>ce of Metaclass. This is the<br />

first point of circularity in <strong>Smalltalk</strong> <strong><strong>an</strong>d</strong> it is worth summarizing:<br />

• All metaclasses are inst<strong>an</strong>ces of Metaclass.<br />

• The metaclass of Metaclass is Metaclass class.<br />

• Metaclass class is a metaclass, it is therefore <strong>an</strong> inst<strong>an</strong>ce of Metaclass.<br />

• Therefore the metaclass of Metaclass is <strong>an</strong> inst<strong>an</strong>ce of Metaclass.<br />

This is illustrated in Figure 32.5. This figure shows that <strong>an</strong> object such as <strong>an</strong> array is <strong>an</strong> ins t<strong>an</strong>ce of the<br />

class Array. In turn Array is <strong>an</strong> inst<strong>an</strong>ce of its metaclass Array class . This metaclass is <strong>an</strong><br />

inst<strong>an</strong>ce of the class Metaclass, which is <strong>an</strong> inst<strong>an</strong>ce of its own metaclass Metaclass class .<br />

And as has been said, Metaclass class is <strong>an</strong> inst<strong>an</strong>ce of Metaclass (see what I me<strong>an</strong> about the<br />

terminology!).<br />

32.5.3 Inst<strong>an</strong>ce relationships for classes <strong><strong>an</strong>d</strong> metaclasses<br />

Behaviour<br />

Behaviour<br />

class<br />

ClassDescript<br />

ion<br />

ClassDescript<br />

ion 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 />

aDictionary<br />

Dictionary<br />

Dictionary<br />

class<br />

Figure 32.6: Inst<strong>an</strong>ce relationships<br />

To complete the expl<strong>an</strong>ation being given, consid er Figure 32.6. This illustrates the inst<strong>an</strong>ce<br />

relationships between classes, their metaclasses, the Metaclass <strong><strong>an</strong>d</strong> the Metaclass class. Note<br />

273

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

Saved successfully!

Ooh no, something went wrong!