Saturday 12 January 2013

Create a new Class in Pharo Smalltalk

Amend the package's sample code - changing "Object" to the class you want to sub-class, and  put the name of the new class, prefixed by #   (The subclass message gets sent to the object you specified, with a parameter of the name you want to give to the new sub-class).

Action-click, then accept (Cmd-s)

On accept, the system, executes the code.

By convention, if a class defines a method named initialize, it will be called right after the object is created.

The first message to send in an initialize method is generally to call the parent class's initialize method, via super initialize.


Open a workspace, and type myNewClassName new    Select it, and inspect it 

The inspector has three panes - the left pane lists the instance variables, and the bottom-right pane is a workspace who's self is bound to the object selected in the browser.
 


No comments: