This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: Declaring Announcements
Feed Title: Richard Demers Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rademers-rss.xml
Feed Description: Richard Demers on Smalltalk
In Relating Announcements to Classes, I made the point that it would be desirable for classes whose instances announce Announcements (wierd wording) to be able to respond to two messages:
#allAnnouncements which returns the Set of Announcements announced by instances of the class. This would include Announcements announced by superclasses. A Parts-like application generator might be a sender of this message.
#declaredAnnouncements which returns the Set of Announcements announced by the class but not its superclasses. Documentation tools, such as SmalltalkDoc, would be a sender of this message.
An open question is how to know which Announcements are announced by a particular class. In Announcement Reflections, Travis Griggs looked into a dynamic method that looked at all methods of a class and its superclasses and found the class litterals of Announcements. He ended up dissatisfied with this approach because it failed to distinguish between subscribing and announcing Announcements, and because it failed to handle the inheritence hierarchy of Announcements, themselves. These problems could be overcome with a better algorithm, but there would still remain the performance cost of the required searches and analysis.
An alternative approach would be more declarative. Suppose there was a #declareAnnouncements class method, that was used to specify the Announcements announced by the class (beyond those announced by its superclasses). Whether or not instances of the class actually announce them is a separate issue, as is whether this declaration is "enforced" or not.
Here are the results I would expect.
Assume that ClassA is the superclass of Class B, which is the superclass of ClassC.
Assume that Announcement J is the superclass of Announcement M.
ClassA declares Announcements I, J, K.
For #allAnnouncements it answers I, J, K.
For #declaredAnnouncements, it answers I, J, K.
ClassB declares Announcements M, P, Q.
For #allAnnouncements it answers I, K, M, P, Q. Note that M overrides its superclass Announcement J.
For #declaredAnnouncements, it answers M, P, Q.
ClassC declares Announcements J, R, S.
For #allAnnouncements it answers I, K, P, Q, J, R, S. Note that J replaces its subclass Announcement M.
For #declaredAnnouncements, it answers J, R, S.
An example of #declareAnnouncements is simply
declareAnnouncements
^Set with: I with: J with: K
#allAnnouncements would have the responsibility of obtaining superclass Announcements and applying overrides correctly.