11 maggio 2011

The Observer Pattern and Syntactic Sugar

From the simplicity dept.

The Observer Pattern is a convenient way of updating collaborating objects upon status update. It happens that the .NET Framework and in particular the C# language provides native support for it, in the form of events.

Uhm. This approach to design patterns is incorrect to me since it requires to add a good amount of syntactic sugar only to handle this in a more "integrated" way. The real problem is that in this way language designers and users learn that every and each interesting capability should have its own syntax.

A radically different approach is provided in Smalltalk. The Object (yes, the Object class) provides convenient methods to handle status updates through the updating category of methods: changed, updated, addDependent, etc.

So, what's simpler? :-)