Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do Announcements relate to the classic Smalltalk-80 dependent/change/update mechanism?

With the Announcements framework available in Pharo Smalltalk, is there still a reason to use the classic Smalltalk-80 dependent/change/update mechanism?

like image 496
MartinW Avatar asked Jan 28 '26 07:01

MartinW


2 Answers

Main difference is that an Announcement is a first class object which is propagated from publisher of an event to the subscribers, while in old dependency mechanism only a symbol was sent. A real object adds therefore a lot of flexibility yet preservers the elegance and simplicity of old pub/sub approach.

like image 72
Janko Mivšek Avatar answered Jan 30 '26 23:01

Janko Mivšek


While the basic principle is the same, the Announcements framework is more flexible and IMHO more elegant. For example, you can define a hierarchy of Announcements and handle them pretty much as you handle exceptions. Assuming Ann2 is a subclass of Ann1, you can:

anObject when: Ann1 do: [...]

the block will capture both classes of announcements. Another cool thing is that you can define a handler for a set of announcements instead of a single one. Assuming that Ann3 and Ann4 are announcements, you can:

anObject when: Ann3, Ann4 do: [...]

and the block will be evaluated when any of those announcements are triggered. Finally, since your events are now objects, you can delegate behavior to them, which is really nice. There are a set of posts by Vassili Bykov on the topic that you may find interesting.

Going back to the original question: the only "drawback" I can think of is that you have to go and define a class instead of just using a symbol. But honestly the effort is so low compared to what you gain with Announcements that for me is a no-brainer. I really can't think of any reason not to go with Announcements.

HTH

like image 33
Andrés Fortier Avatar answered Jan 31 '26 01:01

Andrés Fortier