[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[jfriends-ml 13509] Re: 「 The Art of Multiprocessor Programming 」を読む会第 9 回議事録



高橋(智)です。

C#(.NET)で interface と delegate とを設計上使い分けるポイントは?、という疑問ですが、
答えになっているか怪しいですが、
C# in Depth, Second Edition
http://www.manning.com/skeet2/
の「2.1 Delegates」では、以下のように述べられています。
通知目的であればdelegateを使う、ということでしょうか。。。
----抜粋して引用----
... Alternatively, you can think of a delegate type as a single-method interface,
and a delegate instance as an object implementing that interface.
  If that's just gobbledygook to you, maybe an example will help. It's slightly
morbid, but it does capture what delegates are all about. Consider your will --
your last will and testament. It's a set of instructions -- "pay the bills,
make a donation to charity, leave the rest of my estate to the cat," for instance.
You write it before your death, and leave it in an appropriately safe place. After
your death, your attorney will (you hope!) act on those instructions.
  A delegate in C# acts like your will does in the real world -- as a sequence of
actions to be executed at the appropriate time. Delegates are typically used when
the code that wants to execute the actions doesn't know the details of what those
actions should be. For instance, the only reason why the Thread class knows what to
run in a new thread when you start it is because you provide the constructor with a
ThreadStart or ParameterizedThreadStart delegate instacne.
...
-------------------

> A.3.1 スレッド
> P510
> ■C#(.NET)で interface と delegate とを設計上使い分けるポイントは?
>   --> たとえば...
>       --> メソッドが1つならdelegate
>       --> メソッドが2つ以上ならinterface

-- 
高橋智宏
  Java読書会( http://www.javareading.com/bof/ )