-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package Design_Pattern.适配器模式.对象适配器模式; | ||
|
||
public class Phone { | ||
public void typecPhone() { | ||
System.out.println("信息从Typec口的手机输出。"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package Design_Pattern.适配器模式.对象适配器模式; | ||
|
||
public class Test { | ||
public static void main(String[] args) { | ||
Typec2Vga2 typec2Vga1 = new Typec2Vga2(new Phone()); | ||
typec2Vga1.vgaInterface();//适配器将typec转换成vga | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package Design_Pattern.适配器模式.对象适配器模式; | ||
|
||
public class Typec2Vga2 implements Vga{ | ||
|
||
private Phone phone; | ||
|
||
public Typec2Vga2(Phone phone) { | ||
// TODO Auto-generated constructor stub | ||
this.phone = phone; | ||
} | ||
|
||
@Override | ||
public void vgaInterface() { | ||
// TODO Auto-generated method stub | ||
if(phone != null) { | ||
phone.typecPhone(); | ||
System.out.println("接收到Type-c口信息,信息转换成VGA接口中..."); | ||
System.out.println("信息已转换成VGA接口,显示屏可以对接。"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package Design_Pattern.适配器模式.对象适配器模式; | ||
|
||
public interface Vga { | ||
void vgaInterface(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package Design_Pattern.适配器模式.接口适配器模式; | ||
|
||
public abstract class Adapter implements Target{ | ||
public void typec() { } | ||
public void typec2vga() { } | ||
public void typec2hdmi() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package Design_Pattern.适配器模式.接口适配器模式; | ||
|
||
public interface Target { | ||
void typec(); | ||
void typec2vga(); | ||
void typec2hdmi(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package Design_Pattern.适配器模式.接口适配器模式; | ||
|
||
public class Test { | ||
public static void main(String[] args) { | ||
VgaAdapter vgaAdapter = new VgaAdapter(); | ||
vgaAdapter.typec(); | ||
vgaAdapter.typec2vga();//适配器将typec转换成vga | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package Design_Pattern.适配器模式.接口适配器模式; | ||
|
||
public class VgaAdapter extends Adapter{ | ||
|
||
public void typec() { | ||
System.out.println("信息从Typec口的手机输出。"); | ||
} | ||
|
||
public void typec2vga() { | ||
System.out.println("接收到Type-c口信息,信息转换成VGA接口中..."); | ||
System.out.println("信息已转换成VGA接口,显示屏可以对接。"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package Design_Pattern.适配器模式.类适配器模式; | ||
|
||
public class Phone { | ||
public void typecPhone() { | ||
System.out.println("信息从Typec口的手机输出。"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package Design_Pattern.适配器模式.类适配器模式; | ||
|
||
public class Test { | ||
public static void main(String[] args) { | ||
Vga vga=new Typec2Vga1(); | ||
vga.vgaInterface(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package Design_Pattern.适配器模式.类适配器模式; | ||
|
||
public class Typec2Vga1 extends Phone implements Vga{ | ||
@Override | ||
public void vgaInterface() { | ||
// TODO Auto-generated method stub | ||
typecPhone(); | ||
System.out.println("接收到Type-c口信息,信息转换成VGA接口中..."); | ||
System.out.println("信息已转换成VGA接口,显示屏可以对接。"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package Design_Pattern.适配器模式.类适配器模式; | ||
|
||
public interface Vga { | ||
void vgaInterface(); | ||
} |