added adapter example
This commit is contained in:
parent
ddc6253386
commit
312a5276d7
7
src/learn/simple_adapter/Adaptee.java
Normal file
7
src/learn/simple_adapter/Adaptee.java
Normal file
@ -0,0 +1,7 @@
|
||||
package learn.simple_adapter;
|
||||
|
||||
public class Adaptee {
|
||||
public void specificRequest() {
|
||||
System.out.println("Specific Request");
|
||||
}
|
||||
}
|
14
src/learn/simple_adapter/Adapter.java
Normal file
14
src/learn/simple_adapter/Adapter.java
Normal 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();
|
||||
}
|
||||
}
|
9
src/learn/simple_adapter/Main.java
Normal file
9
src/learn/simple_adapter/Main.java
Normal 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();
|
||||
}
|
||||
}
|
5
src/learn/simple_adapter/Target.java
Normal file
5
src/learn/simple_adapter/Target.java
Normal file
@ -0,0 +1,5 @@
|
||||
package learn.simple_adapter;
|
||||
|
||||
public interface Target {
|
||||
void request();
|
||||
}
|
Loading…
Reference in New Issue
Block a user