"이벤트 핸들러"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
63번째 줄: 63번째 줄:
*https://en.wikipedia.org/wiki/Event_(computing)
*https://en.wikipedia.org/wiki/Event_(computing)
*http://terms.naver.com/entry.nhn?docId=822666&cid=42344&categoryId=42344
*http://terms.naver.com/entry.nhn?docId=822666&cid=42344&categoryId=42344
[[분류: 이벤트]]

2021년 10월 14일 (목) 21:00 기준 최신판

1 개요[ | ]

event handler, listener
이벤트 핸들러, 이벤트 처리기, 이벤트 리스너; 리스너
  • 프로그램 내부에서 입력을 받아 처리하는 일종의 콜백 서브루틴

 

2 예시[ | ]

delegate void Notifier (string sender);
 
class Model {
    public event Notifier notifyViews;
    public void Change() { ... notifyViews("Model"); }
}
 
class View1 {
    public View1(Model m) {
        m.notifyViews += new Notifier(this.Update1);
    }
 
    void Update1(string sender) {
        Console.WriteLine(sender + " was changed during update"); 
    }
}
 
class View2 {
    public View2(Model m) {
        m.notifyViews += new Notifier(this.Update2); 
    }
 
    void Update2(string sender) {
        Console.WriteLine(sender + " was changed"); 
    }
}
 
class Test {
    static void Main() {
        Model model = new Model();
 
        new View1(model);
        new View2(model);
        model.Change();
    }
}

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}