Good interfaces gone bad
Noel J. Bergman
noel at devtech.com
Fri Jun 22 16:08:08 UTC 2001
> it's natural to pop an #asFoo method into String to make converstion
If String>>as<X> was taken any further than it is (and ideally a few of them
should be moved), it would be a good example of a bad implementation
pattern. It increases the surface area of String, coupling it to more and
Instead, X>>fromString: would serve the exact same purpose, semantically
represent the encapsulated behavior in the proper place, and leave the
surface area of String at a minimum.
For example, could one seriously suggest that "Color fromString: '#FFCCAA'"
is unclear or inconvenient compared to '#FFCCAA' asColor", or that it would
be worth polluting the String interface for the perceived convenience, were
someone so inclined?
Don't focus too much on String. String is just an example, inspired by the
"it's natural" comment above, but the point is that it should not be a
responsibility of String to convert itself to/from the myriad of other
objects. And if something isn't an object's responsibility, it shouldn't be
in the interface.
And when did we get away from the notion of responsibility, anyway?
More information about the Squeak-dev