Delegation
・あるクラスの処理の一部をあるクラスに任せる
・他のクラスへメッセージを送る
・特定のアクションに反応するために使われる
・デリゲートを実装する時に考えることは何を委譲するか(なんの処理を呼ばせるのか)を決めるだけです。
誰に委譲するか(どこから呼ぶのか)は考えなくて良いです。
なんで嬉しいの
・保守しやすくなる
・循環参照がなくなり、メモリ管理面のメリットが生じる
以下 訳文
Delegation is a design pattern that enables a class or structure to hand off (or delegate) some of its responsibilities to an instance of another type. This design pattern is implemented by defining a protocol that encapsulates the delegated responsibilities, such that a conforming type (known as a delegate) is guaranteed to provide the functionality that has been delegated. Delegation can be used to respond to a particular action, or to retrieve data from an external source without needing to know the underlying type of that source.
Delegationはデザインパターンです。
それは、クラスや構造体に他のタイプに、インスタンスに対して幾つかの責務を手渡すことを可能にします。
デザインパターンは、プロトコルに定義づけられる事によって処理、実行されます。
それは、委任された責務をカプセル化し、適合した型が委任された機能を提供する事ができる事を保証します。
・Delegationは、特定のアクションに反応するために使われる
・あるデータの基本的な型を知る事無しに、外部のソースコードからデータを回収する事ができる。