Creating a class in Pharo is as simple as sending
subclass: message to another class object. But most of the classes are created and modified in a system browser (currently Nautilus).
The most common way to add (and edit classes) in from the system browser In the Nautilus system browser have nothing selected or select a package (first column) or a class (second column). Depending on the selection, the code editor will display a slightly different class template:
|None||Empty class template|
|Package||A class template with pre-filled package name (based on the selected package)|
|Class||An actual definition of the selected class|
By editing the class template and accepting (saving) the changes you will create a class (or modify an existing one if a class with the same name exists)
In Pharo everything is an object, and every object responds to messages. So if you evaluate the following code
Object subclass: #MyClass
Object will create for you its subclass called MyClass. If you don't have any particular superclass in your mind it's advised to subclass from
Object but this brings a tautological confusion into the previous example. Let's say that you want to create a class PriorityStack with class Stack as a superclass, then you need to evaluate:
Stack subclass: #PriorityStack
You can create classes without names that are not installed in the system by sending
newAnonymousSubclass to a class.
anonymousSet := Set newAnonymousSubclass
will assign an anonymous subclass of Set to
anonymousSet variable. Then you can compile methods in this class and instantiate it, or swap it with a real class.
Useful for test resources of for proxying