I am writing a collection that accepts a time parameter, the purpose is that after that specified amount of time have passed the element won't be present in the collection.
I want the user of this collection to be able to act when an item is removed from the collection under this circumstance. I have two different ways of achieving this, but I am unsure which I should take. Both approaches feels different, but the end result is pretty much the same.
I am asking this question since I may not notice a small (or large) difference between the two and I was hoping to get guidance.
Approach A: Have an event such as OnRemovalDueToTimeout which expects some function that receive an element (e.g void foo(T removedElement)). upon removal I would raise the event
Approach B: Receive a delegate with the same signature as above and call that delegate when an element times out.