Variable Size Objects

Damien Cassou, St├ęphane Ducasse and Luc Fabresse

Variable Size Instances?

Array new: 10
> #(nil nil nil nil nil nil nil nil nil nil)
Array new: 5
> #(nil nil nil nil nil)

Yes arrays can have different sizes

What You Will Learn


Variable Class Definition

Use message variableSubclass: instead of subclass:


ArrayedCollection variableSubclass: #Array
	instanceVariableNames: ''
	classVariableNames: ''
	package: 'Collections-Sequenceable'

Example Variable Class


Object variableSubclass: #StrangePoint
        instanceVariableNames: 'x y'
        classVariableNames: ''
        package: 'Collections-Sequenceable'


Variable Class Instantiation and Index Access

| a |
a := Array new: 4.
a at: 2 put: 'lulu'.
a at: 1
> nil
a at: 2 
> 'lulu'

Classes with Different Shape

Refining the Variable Part

Indexed Named Definition Method Examples
No Yes #subclass:... Color
Yes No #variableSubclass: AdditionalMethodState
Yes No #variableByteSubclass: ByteString
Yes No #variableWordSubclass: Bitmap

Some methods related to class types: isPointers, isBits, isBytes, isFixed, isVariable


What You Should Know