12 August 2016

Adapter Design Pattern in Java

Adapter Design Pattern
Java 2016
package Demo12;

public class User { 
 // Client
 public static void main(String[] args) {
  ChargerAdapter c = new ChargerAdapter();
  c.charger();
 }
}
package Demo12;

public class ChargerAdapter {
 // Adapter
 private ChargerAdaptee adaptee;

 public void charger() {
  adaptee = new ChargerAdaptee();
  adaptee.plug();
 }
}
package Demo12;

public class ChargerAdaptee {
 // Do anything
 public void plug() {
  System.out.println("Plug Nokia");
  System.out.println("plug Samsung");
 }
}
Ouput:
plug Nokia
plug Samsung

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang