1 /**
   2  * AdapterPattern Example
   3  */
   4 
   5 /**
   6  * Adaptee
   7  */
   8 class Banner {
   9     private String string;
  10     public Banner(String string) {
  11         this.string = string;
  12     }
  13     public void showWithParen() {
  14         System.out.println("("+string+")");
  15     }
  16     public void showWithAster() {
  17         System.out.println("*"+string+"*");
  18     }
  19 }
  20 
  21 /** 
  22  * Target
  23  */
  24 interface Print {
  25     public abstract void printWeak();
  26     public abstract void printStrong();
  27 }
  28 
  29 /**
  30  * Adapter
  31  */
  32 class PrintBanner extends Banner implements Print {
  33     public PrintBanner(String string) {
  34         super(string);
  35     }
  36     public void printWeak() {
  37         showWithParen();
  38     }
  39     public void printStrong() {
  40         showWithAster();
  41     }
  42 }
  43 
  44 public class AdapterBanner {
  45     public static void main(String[] args) {
  46         Print p = new PrintBanner("Hello");
  47         p.printWeak();
  48         p.printStrong();
  49     }
  50 }
web biohackers.net