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.

eturn operator in a method. Thus allowing a method to return from different points depending on the<br />

execution path taken through the method.<br />

34.1.5 Cascading<br />

The cascade operator, represented by a comma ( , ) c<strong>an</strong> be used to send a series of messages to the same<br />

object (which is only referenced once). For example:<br />

C<strong>an</strong> be re-written as:<br />

Tr<strong>an</strong>script cr.<br />

Tr<strong>an</strong>script show: 'John Hunt'.<br />

Tr<strong>an</strong>script: tab.<br />

Tr<strong>an</strong>script show: '1995'.<br />

Tr<strong>an</strong>script cr.<br />

Tr<strong>an</strong>script cr;<br />

show: 'John Hunt';<br />

tab;<br />

show: '1995';<br />

cr.<br />

34.2 Literals <strong><strong>an</strong>d</strong> variables<br />

34.2.1 Literals<br />

Literals are const<strong>an</strong>t objects such as numbers, characters, strings, symbols etc.<br />

Numbers are a sequence of numeric characters with <strong>an</strong> optional decimal point <strong><strong>an</strong>d</strong> <strong>an</strong> optional minus<br />

sing. Example of numbers are:<br />

8 12.7 -44.7 0.0009<br />

In <strong>Smalltalk</strong> a number is positive unless otherwise stated. there is therefore no need for a unary<br />

plus sign. Numbers c<strong>an</strong> also be represented in other bases, by preceding them with a radix <strong><strong>an</strong>d</strong><br />

the letter “r”:<br />

6r145<br />

8r5E<br />

Characters are individual letters <strong><strong>an</strong>d</strong> are distinctly different to a string containing only a single letter.<br />

They are represented by a single character preceded by a “$” symbol. For example:<br />

$a $d $’ $+ $4<br />

Strings are collections of characters encompassed within single quotes. They c<strong>an</strong> possess spaces, under<br />

bars etc. For example:<br />

'Hello World'<br />

Symbols are special objects that represent unique entities in the <strong>Smalltalk</strong> system. These are<br />

represented using a leading the hash (#) symbol.<br />

#temp<br />

#john<br />

34.2.2 Variables<br />

Variable names describe accessible variables. Variable names are identifiers made up of letters <strong><strong>an</strong>d</strong><br />

digits with <strong>an</strong> initial letter:<br />

some<strong>Object</strong> MyCar totalNumber<br />

285

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

Saved successfully!

Ooh no, something went wrong!