Hi
Sorry for the late reply
Where did you read that? What was the context?
Some article on delegates had a link to the following interview:
http://www.artima.com/intv/simplexity2.html
In the link above they don’t explicitly say that we should only use
( for the most part ) use single-cast delegates, but the site that
provided the link, did argue that
I assume you don't mean to ask what the term "single-cast" means, but
rather what the use of that term in the context of some advice is intended
to mean.
That said, the question still doesn't make much sense. A delegate is
immutable. When you "create a delegate object", at that point it is
established how many methods will be invoked when the delegate itself is
invoked. This means that asking how the delegate should be used "during
its whole lifetime" isn't meaningful; the delegate can be used only in one
way ever during the entire lifetime of the delegate.
I understand that if we have delegate "D = some_method", then
"D+= some_other_method" creates a new delegate , with both some_method
and some_other_method in its invocation list.
What I meant was, should D reference only be used to point to
delegates that only ever invoke one method at the time
I see no reason to think they should be. It is probably true that the
invocation list for most delegate instances has only just one method; the
multi-cast aspect of delegates is not commonly used, even for events. But
that's a statement of how they _are_ used, not how they _should be_ used.
What do you mean by "demand"? How is class X going to use this method in
class Y? How is class X in a position to make any "demands" on class Y?
I was sort of generalizing, so I didn’t have any particular code
implementation in mind. By class ‘X demanding from class Y’ I meant
that if class Y wants certain services from class X, then it should
register a method ( with correct signature ) with a delegate D
What do you mean by "reside inside"? Are you talking about a referenceto
the delegate instance being stored in a member field somewhere?
I’m wondering whether delegate reference ( the one we will use to call
event handlers ) should be declared inside class X or Y?
In actuality, a very common way for one class to "demand" that some other
class implement a method with a certain signature is to describe that
method in an interface and then expect the other class to implement that
interface.
Delegates can be thought of as a very simple, single-method interface.
For one class X to "demand" some other class Y implements a method with a
specific signature but without a specific name (as would be required for
an interface), the _only_ possibility is for the class Y to somehow create
a delegate referencing the implementation and passing it to class X at
some point.
I assumed there could be some well known class X ( well known in the
programming circles ) and this class X would do “favors” to any class
that would register its methods with specific delegate object. Point
being that it is assumed that programmers of class Y know the method
signature class X demands ( if they know the method signature, then
delegate object could also be implemented inside X class )
This could be via a named property, but then what would the point of that
be? If class Y has to have some specific named member to support your
"demand", it might as well be the method itself. More generally, this is
the problem with storing the delegate reference in class Y. If the
reference is in class Y, then class X needs a way to access it, and if it
has a way to access it, then it could just as easily have had a way to
access the method itself.
* But by having Y to implement delegate object instead of allowing X
to access the method directly, X class doesn’t have to know the name
of a method in class Y
* Anyways, I thought there was some general agreement in which of the
two classes should the “actual ”delegate reference be declared ( by
“actual” I mean one that will be used to fire up a delegate – while
both X and Y may have numerous references pointing to the same
delegate object as this “actual” delegate reference is pointing at,
but it will be the “actual” reference that will ultimately be used to
call the event handlers).
thank you all