How many subclasses does a class have?

sqrmax at cvtci.com.ar sqrmax at cvtci.com.ar
Wed Jun 17 14:22:11 UTC 1998


Hi.

data := Dictionary new.

Object withAllSubclasses do: [:each | data at: each subclasses size put: 
(data at: each subclasses size ifAbsent: [0]) + 1]

data inspect


In my image this gave out:

0 subclasses: 885
1 subclass: 173
2 subclasses: 104
3: 20
4: 30
5: 8
6: 8
7: 4
8: 4
9: 8
10: 4
15: 2
16: 2
17: 2
169: 2


Now comes the funny part. What is the average amount of subclasses per 
class? Answer: 1 / amountOfClasses + 1. That is, almost 1. Amazing, isn't it?

Proof.

For the average we need the amount of subclasses, and on the other hand the 
amount of classes. But each is one of the others except nil's subclasses. 
There's only one of those (Object), then the average of subclasses per class is

(amountOfSubclasses + 1) / amountOfClasses =
(amountOfClasses + 1) /. amountOfClasses =
1 / amountOfClasses + 1,

that is, arbitrarily close to 1 as the amount of classes increase.

Andres.





More information about the Squeak-dev mailing list