Guided Tour
In this section, we guide you through the process of
o creating a problem
o running reviews
o browsing the results
o fixing the problem
Creating a Problem
Create the following class and methods. Note that the method named:age: intentionally introduces a typing error to demonstrate a message generated by the code review. Please type the method as shown. You will see the reference to the error in Fixing the Problems.
Person class
Object subclass: #Person
instanceVariableNames: 'name age '
classVariableNames: ''
poolDictionaries: ''
 
Person public class methods
named: aString age: anInteger
"Answer a new instance of the receiver whose name is aString
and age is anInteger."
^self new
mane: aString;
age: anInteger
 
Person public instance methods
age
^age
 
happyBirthday
"The receiver has had a birthday.
Display a Happy Birthday greeting, and make him/her a year older."
age := age + 1.
System message: ('Happy ', self age printString, ' Birthday, ', self name, '!')
 
name
"Answer the name (String) of the receiver."
^name
 
Person private instance methods
age: anInteger
"Set the age (Integer) of the receiver to anInteger."
age := anInteger
name: aString
"Set the name (String) of the receiver to aString."
name := aStringFramework
Running Reviews
After you have added the Person class and its methods, run Code Critic as follows.
1. Open a Classes Browser and select the Person class.
2. Select Classes > Tool > Review > Class....
3. When the Code Critic Options dialog opens, click OK.
Code Critic runs all reviews on the Person class
Browsing the Results
After the reviews run, the Code Critic Results Browser displays the results. To browse the results:
1. In the left list, select Method:Direct state variable access.
The right list shows the results of the review type.
2. In the right list, select method Person>>#happyBirthday.
The text area under the lists shows the source code of the method and highlights age. This indicates that the instance variable age is accessed directly without an accessor. The status area above the text area showing the source code provides additional information about the problem.
3. Select the method again.
The next problem is highlighted automatically. You can also click Next to advance to the next problem.
Fixing the Problems
When the text of the method is displayed in the text area:
1. Correct the problem by modifying the method text to:
happyBirthday
"The receiver has had a birthday.
Display a Happy Birthday message, and increment his/her age."
self age: self age + 1.
System message: ('Happy ', self age printString, ' Birthday, ', self name, '!')
2. Save the changed method.
When the problem is corrected, Code Critic automatically removes the method from the Code Critic Results Browser.
3. Select the review Method:Missing method comment and method Person>>#age. (The method is missing a method comment.)
4. Modify the method to the following and save it:
age
"Answer the age (Integer) of the receiver."
^age
5. Select the review Method:Sent but not implemented and method Person
class>>#named:age:. (The method has a spelling error: #mane:
should be #name:.)
6. Correct the spelling error and save the method. The method is now:
named: aString age: anInteger
"Answer a new instance of the receiver whose name is aString
and age is anInteger."
^self new
name: aString;
age: anInteger;
yourself
7. Correct the remaining problems in a similar manner.
Last modified date: 08/14/2015