Hi
So, on your place, if you really need a lot of classes with announcer
capabilities, you can do it like that:
Object subclass: #ObjectWithAnnouncer
instvars: 'announcer'
Object subclass: #AnnouncerinstanceVariableNames: 'registry'classVariableNames: ''poolDictionaries: ''category: 'Announcements-Core'
then may implement same protocol as in Announcer in it, which will
simply delegate to announcer ivar.
And i bet, you don't want to expose full Announcer protocol there,
while probably you may want to implement some convenience protocols,
which Announcer lacking.
So, at the end by subclassing from ObjectWithAnnouncer you will be
reusing its capabilities in each and every subclass of it, but by
delegating real job, you are free from worrying about dealing with
implementation detail and exposing unwanted state/protocols to its
users.
Another aspect of it, is when i see:
ObjectWithAnnouncer subclass: #MyDomainObject
it tells me, aha.. so some (at least this one) of his domain objects
having announcers,
and the valid protocols is defined in ObjectWithAnnouncer.
but when i see
Announcer subclass: #MyDomainObject
i starting to be uncertain: is Announcer private there or public?
can i send messages like #basicSubscribe: to your domain object and expect that
it will be handled correctly? Or do i allowed to subscribe directly at
all, because maybe
domain object has some specific protocol(s) and ways to do that..
Every such question and uncertainty for coder means more time, more
errors, and less productivity.
--
Best regards,
Igor Stasenko.