LoginSignup
0
0

More than 5 years have passed since last update.

Delegation

Last updated at Posted at 2015-11-10

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は、特定のアクションに反応するために使われる
・あるデータの基本的な型を知る事無しに、外部のソースコードからデータを回収する事ができる。

参考
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html#//apple_ref/doc/uid/TP40014097-CH25-ID276

0
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0