Navigation:  Appendix B: Dolphin Pattern Book > Method Patterns >

New Method

Previous pageReturn to chapter overviewNext page


In Smalltalk, all objects are instances of a particular class and these instances communicate with one another by sending messages. When defining a New Class (or enhancing an existing one) how do we specify the behavior for messages that will be sent to the instances.


Implement methods to specify how an object responds to a particular message. The Method Name must be the same as the message selector.

It is not necessary for every class to provide methods for all of the possible messages it may receive. The object-oriented concept of inheritance can be used to allow behaviour to be inherited from a superclass that already provides an appropriate method for a particular message selector.

Add a new method using the Class Browser:

1.Open the browser and select the appropriate class to which the method is to be added. Bear in mind that there are instance methods and class methods and you must choose the appropriate Instance or Class mode in the browser to make sure the new method goes on the correct "side".
2.Choose an appropriate Method Name to describe the method. This is the same as the message selector that will be used to invoke it.
3.Use the Method/New command to clear out the source pane in the browser and type the new method definition. Use Workspace/Accept (Ctrl+S) to compile it and commit the change to the current class.
4.Categorize the method using Method/Add Category. Including the method in an appropriate category can make it easy to find for developers who are unaccustomed with the class.

Related Patterns

Method Name