Паттерн проектирования Adapter
public class Main {
public static void main(String[] args) {
AmericanSocket americanSocket = new SimpleAmericanSocket();
EuropeanSocket europeanSocket = new SocketAdapter(americanSocket);
Radio radio = new Radio();
radio.listenMusic(europeanSocket);
}
}
class SimpleAmericanSocket implements AmericanSocket
{
@Override
public void getPower() {
System.out.println("AmericanSocket 110 volt");
}
}
class SocketAdapter implements EuropeanSocket
{
AmericanSocket americanSocket;
public SocketAdapter(AmericanSocket americanSocket) {
this.americanSocket = americanSocket;
}
@Override
public void getPower() {
this.americanSocket.getPower();
}
}
interface AmericanSocket{
void getPower();
}
interface EuropeanSocket{
void getPower();
}
class Radio {
public void listenMusic(EuropeanSocket europeanSocket)
{
europeanSocket.getPower();
}
}
Last updated