Pattern: Method Category
Context
In Dolphin Smalltalk, methods are assigned into categories.
Method categories group together associated methods and make them
easier to find in the Class Hierarchy Browser. A method may
belong to several categories. We need a consistent way of
deciding on how to choose the categories for a new method and how
to name new categories that are created when no existing category
is suitable.
Solution
First of all, use the Method/Suggest Category
feature in the Class Hierarchy Browser to offer a possible
category set in which to place the method. This feature uses an
instance of MethodCategorizationPolicy to decide on suitable
categories. You can augment this policy if required. If you want
to add the method to several categories then you can repeat this
step any number of times.
If no suitable suggestions are presented then proceeed as
follows:
- Decide first on the features of the class in which the
method resides. Often there will be a fundamental feature
which describes the main purpose of the class. This may
be inherited from the purpose of the superclass or it may
be related to that of one or more instance variables. The
other features, apart from the fundamental, can often be
derived from the aspects of the class.
- Decide if the method deals with this fundamental nature.
If so, consult the list of Basic
Categories and decide to which category it belongs.
Add the method to this category.
- Otherwise, decide if the method belongs to one of the
additional features of the class. Then consult the list
of Basic Categories and
decide to which category the feature belongs. Add the
method to this category pre-pended with the feature name
and a hyphen.
- If the method doesn't belong to any existing feature,
then consider if a new feature should be attributed to
the class. If so, re-apply step 2.
- Otherwise, you can usually add the method to the accessing
category as a catch-all.
Related Patterns