public void Advise(Boss boss) { _boss = boss; }
public void DoWork() {
Console
if( _boss != null ) _boss
Console
if( _boss != null ) _boss
Console
if( _boss != null ) {
int grade = _boss
Console
}
}
private Boss _boss;
}
class Boss {
public void WorkStarted() { /* 老板不關心
public void WorkProgressing() { /*老板不關心
public int WorkCompleted() {
Console
return
}
}
class Universe {
static void Main() {
Worker peter = new Worker();
Boss boss = new Boss();
peter
peter
Console
Console
}
}
接口
現在
void WorkStarted();
void WorkProgressing();
int WorkCompleted();
}
class Worker {
public void Advise(IWorkerEvents events) { _events = events; }
public void DoWork() {
Console
if( _events != null ) _events
Console
if(_events != null ) _events
Console
if(_events != null ) {
int grade = _events
Console
}
}
private IWorkerEvents _events;
}
class Boss : IWorkerEvents {
public void WorkStarted() { /* 老板不關心
public void WorkProgressing() { /* 老板不關心
public int WorkCompleted() {
Console
return
}
}
委托
不幸的是
他的老板還是抱怨得很厲害
[
From:http://tw.wingwit.com/Article/program/net/201311/15527.html