-
Notifications
You must be signed in to change notification settings - Fork 1
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
4 changed files
with
56 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,10 @@ | ||
package gof.dp.adapter; | ||
|
||
public class AdapterMain { | ||
public static void main(String[] args) { | ||
Print p = new PrintBanner("Hello"); | ||
p.printWeak(); | ||
p.printStrong(); | ||
} | ||
|
||
} |
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,18 @@ | ||
package gof.dp.adapter; | ||
|
||
public class Banner {//Adptee Class | ||
private String str; | ||
public Banner(String str){ | ||
this.str = str; | ||
} | ||
|
||
public void showWithParen(){ | ||
System.out.println("(" +str+ ")"); | ||
} | ||
|
||
public void showWithAster(){ | ||
System.out.println("*" +str+ "*"); | ||
} | ||
|
||
|
||
} |
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 gof.dp.adapter; | ||
|
||
public interface Print {//Target class | ||
|
||
public abstract void printWeak(); | ||
public abstract void printStrong(); | ||
} |
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 gof.dp.adapter; | ||
|
||
public class PrintBanner implements Print{//Adapter | ||
|
||
private Banner banner; | ||
|
||
public PrintBanner(String str){ | ||
this.banner = new Banner(str); | ||
} | ||
|
||
@Override | ||
public void printWeak() { | ||
banner.showWithParen(); | ||
} | ||
|
||
@Override | ||
public void printStrong() { | ||
banner.showWithAster(); | ||
} | ||
|
||
} |