アダプタパターン
3698 ワード
別のインターフェイスクライアントにクラスのインターフェイスを変換します.アダプターは、互換性のないインターフェイスのため、クラスが一緒に動作できません.
ターゲット:クライアントが使用するドメイン固有のインターフェイスを定義します. アダプター:インターフェイスアダプターをターゲットインターフェイスに適応します. Adaptee :適応が必要な既存のインターフェイスを定義します. クライアント:ターゲットインターフェイスに準拠するオブジェクトとのコラボレーション. コード
参加者
コード
public class Main {
public static void main(String[] args) {
Target target = new Adapter();
target.request();
}
}
public interface Target {
void request();
}
public class Adapter implements Target {
Adaptee adaptee = new Adaptee();
@Override
public void request() {
adaptee.specificRequest();
}
}
public class Adaptee {
void specificRequest() {
System.out.println("Called specificRequest()");
}
}
出力
Called specificRequest()
エディエルジュリアン61
/
デザインパターン
メインデザインパターン
アイドル・ Sep 27・ 1分読む
#designpatterns
#creational
#structural
#behavioral
Reference
この問題について(アダプタパターン), 我々は、より多くの情報をここで見つけました
https://dev.to/eidher/adapter-h52
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
public class Main {
public static void main(String[] args) {
Target target = new Adapter();
target.request();
}
}
public interface Target {
void request();
}
public class Adapter implements Target {
Adaptee adaptee = new Adaptee();
@Override
public void request() {
adaptee.specificRequest();
}
}
public class Adaptee {
void specificRequest() {
System.out.println("Called specificRequest()");
}
}
Called specificRequest()
エディエルジュリアン61 / デザインパターン
メインデザインパターン
アイドル・ Sep 27・ 1分読む
#designpatterns
#creational
#structural
#behavioral
Reference
この問題について(アダプタパターン), 我々は、より多くの情報をここで見つけました https://dev.to/eidher/adapter-h52テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol