From 312a5276d766ddcf653687fa9efd35e09093f860 Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Mon, 14 Oct 2024 08:56:56 +0200 Subject: [PATCH] added adapter example --- src/learn/simple_adapter/Adaptee.java | 7 +++++++ src/learn/simple_adapter/Adapter.java | 14 ++++++++++++++ src/learn/simple_adapter/Main.java | 9 +++++++++ src/learn/simple_adapter/Target.java | 5 +++++ 4 files changed, 35 insertions(+) create mode 100644 src/learn/simple_adapter/Adaptee.java create mode 100644 src/learn/simple_adapter/Adapter.java create mode 100644 src/learn/simple_adapter/Main.java create mode 100644 src/learn/simple_adapter/Target.java diff --git a/src/learn/simple_adapter/Adaptee.java b/src/learn/simple_adapter/Adaptee.java new file mode 100644 index 0000000..4c53245 --- /dev/null +++ b/src/learn/simple_adapter/Adaptee.java @@ -0,0 +1,7 @@ +package learn.simple_adapter; + +public class Adaptee { + public void specificRequest() { + System.out.println("Specific Request"); + } +} diff --git a/src/learn/simple_adapter/Adapter.java b/src/learn/simple_adapter/Adapter.java new file mode 100644 index 0000000..bed7989 --- /dev/null +++ b/src/learn/simple_adapter/Adapter.java @@ -0,0 +1,14 @@ +package learn.simple_adapter; + +public class Adapter implements Target { + private Adaptee adaptee; + + public Adapter(Adaptee adaptee) { + this.adaptee = adaptee; + } + + @Override + public void request() { + adaptee.specificRequest(); + } +} diff --git a/src/learn/simple_adapter/Main.java b/src/learn/simple_adapter/Main.java new file mode 100644 index 0000000..0074e64 --- /dev/null +++ b/src/learn/simple_adapter/Main.java @@ -0,0 +1,9 @@ +package learn.simple_adapter; + +public class Main { + public static void main(String[] args) { + Adaptee adaptee = new Adaptee(); + Target adapter = new Adapter(adaptee); + adapter.request(); + } +} diff --git a/src/learn/simple_adapter/Target.java b/src/learn/simple_adapter/Target.java new file mode 100644 index 0000000..9931439 --- /dev/null +++ b/src/learn/simple_adapter/Target.java @@ -0,0 +1,5 @@ +package learn.simple_adapter; + +public interface Target { + void request(); +}