added adapter example

This commit is contained in:
Louis Heredero 2024-10-14 08:56:56 +02:00
parent ddc6253386
commit 312a5276d7
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
4 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,7 @@
package learn.simple_adapter;
public class Adaptee {
public void specificRequest() {
System.out.println("Specific Request");
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -0,0 +1,5 @@
package learn.simple_adapter;
public interface Target {
void request();
}