地址类
public class Address {public void street() {System.out.println("普通的街道");}public void zip() {System.out.println("普通的邮政编码");}public void city() {System.out.println("普通的城市");}
}
荷兰地址类
public class DutchAddress {public void straat() {}public void postcode() {}public void plaats() {}
}
荷兰地址适配器类
public class DutchAddressAdapter extends DutchAddress {private Address address;public DutchAddressAdapter(Address address) {this.address = address;}public void straat() {address.street();}public void postcode() {address.zip();}public void plaats() {address.city();}
}
演示类
public class Test {public static void main(String[] args) {Address addr = new Address();DutchAddress addrAdapter = new DutchAddressAdapter(addr);System.out.println("the DutchAddress");testDutch(addrAdapter);}private static void testDutch(DutchAddress addr) {addr.straat();addr.postcode();addr.plaats();}
}
演示结果