Best way to extend the behavior of a Pharo Smalltalk class?

I want to extend the String class using the method of creating a URL string from a string. I found a link here that shows how you can move extensions into your own package:

Smalltalk Daily 07/13/10: Expanding Behavior II .

However, I cannot find the move to package option in Pharo Smalltalk. Is it possible to simply extend the kernel class with a new method, or is there a better way?

+6
smalltalk pharo
source share
2 answers

In Pharo or Squeak, put extension methods for MyPackage in the method category called *mypackage (or if you want to be more descriptive *mypackage-slug ).

The methods in these categories automatically apply to the MyPackage package (at least from Monticello's point of view)

+8
source share

"Is it possible to simply extend the kernel class with a new method, or is there a better way?"

There are trade-offs in this decision. In fact, Pharo had String → asUrl until very recently, when it was removed as part of a system cleanup . On the one hand, some believe that a bad style (see Kent Beck Best Practices) has methods for converting between objects that do not have similar protocols (semantically similar). In addition, this leads to bloated class kernels (e.g. String and Object). However, there may be a good reason in your own application that balances these factors, and since you are packing them in your application and not in the system, get out.

+8
source share

All Articles