When a shape is added, TShapeList creates a TShapeNotification with a TShapeInterest for that shape and calls Notify twice--once to send the notification to receivers that registered interest in the addition of that particular shape and once to send it to receivers that registered interest in the addition of any shape. Removal of a shape works similarly.
Here is the change to the interface of TShapeList:
class TShapeList : public TNotifier { public: TShapeInterest GetAddedThisShapeInterest(const TShape&); // TShapeNotification TShapeInterest GetRemovedThisShapeInterest(const TShape&); // TShapeNotification // ... }
TShapeInterest TShapeList::GetAddedThisShapeInterest(const TShape& shape) { const TToken kAddedThisShape("kAddedThisShape"); return TShapeInterest(this, kAddedThisShape, shape); }
The TShapeNotification contains an instance of TShapeInterest, in case receivers want to look at it.
void TShapeList::AdoptShape(MGraphic* shape) { fShapes.Add(shape); TShapeNotification notification(GetAddedThisShapeInterest(shape), *shape); Notify(notification); // sent using the shape interest Notify(notification, GetAddedShapeInterest()); // sent using different interest }