Skip to content

Commit f1835c7

Browse files
author
laileon
committed
adapter
1 parent ead1912 commit f1835c7

File tree

5 files changed

+47
-63
lines changed

5 files changed

+47
-63
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.blankj.custom.desingn_pattern.adapter;
2+
3+
public class Adapter {
4+
// public class Scanner{
5+
// public void read(Readable material){
6+
// material.read();
7+
// }
8+
// }
9+
//
10+
// public interface Readable{
11+
// void read();
12+
// }
13+
// public class TXT implements Readable{
14+
// ...
15+
// public void read(){
16+
// //读取txt文件
17+
// }
18+
// ...
19+
// }
20+
//
21+
// public class HTML{
22+
// public void toReadableFormat(){
23+
// //html文件也可以被读取,但是它并没有继承Readable接口,所以无法被Scanner
24+
// 识别
25+
// }
26+
// }
27+
//
28+
// //这里才是适配器模式
29+
// public class HTMLAdapter implements Readable{
30+
// ...
31+
// private HTML html;
32+
// public HTMLAdapter(HTML html){this.html = html}
33+
// public void read(){
34+
// html.toReadableFormat();
35+
// }
36+
// ...
37+
// }
38+
//
39+
// //这时候两个文件都可以被读取了
40+
// public class Test{
41+
// public static void main(String[] args){
42+
// Scanner s = new Scanner();
43+
// s.read(new TXT());
44+
// s.read(new HTMLAdapter(new HTML()));
45+
// }
46+
// }
47+
}

src/com/blankj/custom/desingn_pattern/adapter/AdapterDemo.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/com/blankj/custom/desingn_pattern/adapter/MyAdapter.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/com/blankj/custom/desingn_pattern/adapter/Windows.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/com/blankj/custom/desingn_pattern/adapter/WindowsAdapter.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)