05.08.2014 Views

here - Stefan-Marr.de

here - Stefan-Marr.de

here - Stefan-Marr.de

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

4. Experimentation Platform<br />

Classes and Methods Object fields are <strong>de</strong>fined with a syntax similar to local<br />

variables in methods of other Smalltalk versions. In this case, every object has<br />

a class field, referring to the object’s class.<br />

Note that SOM uses object-based encapsulation. Thus, only the object itself<br />

has access to its fields. This is different from class-based encapsulation as<br />

used for instance in Java [Gosling et al., 2012]. In languages with class-based<br />

encapsulation, all objects of a class can access the private fields of other objects<br />

of the same class.<br />

Methods in Smalltalk have either no arguments, one argument when the<br />

method selector is a special symbol, or they use so-called keyword messages,<br />

which indicate the arguments with colons.<br />

The first method in line 4 is a simple method without arguments. It is an<br />

accessor to the class field and directly returns the value. Note the circumflex<br />

(^), which corresponds to the return keyword in other languages. Further<br />

note that the body text of this dissertation refers to methods in source co<strong>de</strong><br />

examples by their selector symbol, i. e., the method name with a preceding<br />

hashmark (#). Thus, line 4 <strong>de</strong>fines the method #class.<br />

Line 5 <strong>de</strong>fines a second method #=, which takes the argument other to<br />

implement object equality by using the reference equality message #==. Examples<br />

for binary messages are #= and #==, which take an extra argument in<br />

addition to the receiver. In this particular case #== refers to its argument as<br />

other. Line 6 <strong>de</strong>fines #== to be implemented via a VM primitive, which checks<br />

the receiver and the argument for reference equality. The #ifNil:ifNotNil:<br />

method <strong>de</strong>fined in line 10 is a convenience method implementing a simple<br />

control structure based on blocks. It is a keyword message with two parameters,<br />

<strong>here</strong> called nilBlock and goBlock.<br />

Blocks are anonymous functions, i. e., lambdas. Depending on the Smalltalk<br />

implementation, they are either full closures or classic restricted blocks as in<br />

Smalltalk-80 [Goldberg and Robson, 1983]. Classic blocks cannot be used once<br />

they left the dynamic extend in which they have been created. Thus, they<br />

cannot be returned from the method in which they were created.<br />

SOM also supports class-si<strong>de</strong> methods and static fields in terms of fields of<br />

the class object. Since classes are objects, the same rules apply and they are<br />

treated i<strong>de</strong>ntically.<br />

Handling of Globals References to classes are treated as lookups of global<br />

variables. Such global variables can also refer to objects other than classes.<br />

However, assignments to globals are ignored and not directly supported by<br />

92

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

Saved successfully!

Ooh no, something went wrong!