Computer Programming with GNU Smalltalk - Free
Computer Programming with GNU Smalltalk - Free
Computer Programming with GNU Smalltalk - Free
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Objects, Messages and Classes: Part II 61<br />
They are only for documentation purposes and appear on IDEs we use for explaining what a class or<br />
method does so that we can get an idea of what it does <strong>with</strong>out looking at its code which would took<br />
much longer and be harder. They do not affect the execution of the program, so, we can omit them.<br />
And the time comes to defining the class and instance methods. We first created a class method:<br />
SubclassName class >> aClassMethod: aParameter [<br />
"Comment to describe this class method"<br />
<br />
]<br />
| localVariable1 localVariable2 |<br />
...<br />
^objectToReturn<br />
We again have a header part and a body part here. The header of the class definition is:<br />
SubclassName class >> aClassMethod: aParameter<br />
SubclassName class >> part of this header tells us that we are going to create a method for the<br />
class, not for the instances of the class. If we'd omitted this part then the method would be a part for the<br />
instances of this class. After this part we specify our method's message. The selector of this message is<br />
aClassMethod:. It takes a parameter named aParameter. Parameters are the names given to the<br />
argument names when they are used in the header of methods, so these words are actually not that<br />
different from arguments and sometimes used in exchange. We may use the parameter names inside our<br />
method to refer to the argument passed to the method.<br />
After specifying the selector we opened the bracket to define the method content which is called the<br />
body of the method:<br />
[<br />
]<br />
"Comment to describe this class method"<br />
<br />
| localVariable1 localVariable2 |<br />
...<br />
^objectToReturn<br />
The content of a method can be made of a comment, a category, some local variables and the<br />
expressions to execute which are shown as three dots. After writing a comment <strong>with</strong>: