1 advantages for delegate function
1.1 decouple the caller class and callee class.They don't need know any internal detail about each other.
1.2 pass some values and handle from caller to callee. Not for from callee to caller!!!
2 sample code
class Callee
{
private Fucntion Dosomething()
{
this.NotifyDelegate();
}
public delegate void Notify();
//declare a delegate function event instance
public event Notify NotifyDelegate;
}
class Caller
{
Callee instanceCallee = new Callee();
Callee.NotifyDelegate + = new Notify(NotifyFromCallee)
private void Function()
{
instanceCallee.Dosomething();
}
private void NotifyFromCallee()
{
//blah, blah, blah
}
}
1.1 decouple the caller class and callee class.They don't need know any internal detail about each other.
1.2 pass some values and handle from caller to callee. Not for from callee to caller!!!
2 sample code
class Callee
{
private Fucntion Dosomething()
{
this.NotifyDelegate();
}
public delegate void Notify();
//declare a delegate function event instance
public event Notify NotifyDelegate;
}
class Caller
{
Callee instanceCallee = new Callee();
Callee.NotifyDelegate + = new Notify(NotifyFromCallee)
private void Function()
{
instanceCallee.Dosomething();
}
private void NotifyFromCallee()
{
//blah, blah, blah
}
}
Comments