Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Smalltalk
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Classes== This is a stock class definition:<ref>{{cite book|last1=Goldberg|first1=Adele|author-link1=Adele Goldberg (computer scientist)|last2=Robson|first2=David|title=Smalltalk-80 The Language|year=1989|publisher=Addison Wesley|isbn=0-201-13688-0|pages=39–53}}</ref> <syntaxhighlight lang="smalltalk"> Object subclass: #MessagePublisher instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'Smalltalk Examples' </syntaxhighlight> Often, most of this definition will be filled in by the environment. Notice that this is a message to the <code>Object</code> class to create a subclass named <code>MessagePublisher</code>. In other words: classes are [[first-class object]]s in Smalltalk which can receive messages just like any other object and can be created dynamically at execution time. ===Methods=== When an object receives a message, a method matching the message name is invoked. The following code defines a method publish, and so defines what will happen when this object receives the 'publish' message. <syntaxhighlight lang="smalltalk"> publish Transcript show: 'Hello World!' </syntaxhighlight> The following method demonstrates receiving multiple arguments and returning a value: <syntaxhighlight lang="smalltalk"> quadMultiply: i1 and: i2 "This method multiplies the given numbers by each other and the result by 4." | mul | mul := i1 * i2. ^mul * 4 </syntaxhighlight> The method's name is <code>#quadMultiply:and:</code>. The return value is specified with the <code>^</code> operator. Objects are responsible for determining dynamically at runtime which method to execute in response to a message—while in many languages this may be (sometimes, or even always) determined statically at compile time. ===Instantiating classes=== The following code: <syntaxhighlight lang="smalltalk"> MessagePublisher new </syntaxhighlight> creates (and returns) a new instance of the MessagePublisher class. This is typically assigned to a variable: <syntaxhighlight lang="smalltalk"> publisher := MessagePublisher new </syntaxhighlight> However, it is also possible to send a message to a temporary, anonymous object: <syntaxhighlight lang="smalltalk"> MessagePublisher new publish </syntaxhighlight>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Smalltalk
(section)
Add topic