package com.company.design.adapter;
public interface Electronic110V {
void powerOn();
}
package com.company.design.adapter;
public interface Electronic220V {
void connect();
}
package com.company.design.adapter;
public class HairDryer implements Electronic110V{
@Override
public void powerOn() {
System.out.println("헤어 드라이기 110v on");
}
}
package com.company.design.adapter;
public class AirConditiional implements Electronic220V{
@Override
public void connect() {
System.out.println("에어컨 220v on");
}
}
package com.company.design.adapter;
public class Cleaner implements Electronic220V{
@Override
public void connect() {
System.out.println("청소기 220v on");
}
}
package com.company.design;
import com.company.design.adapter.Cleaner;
import com.company.design.adapter.Electronic110V;
import com.company.design.adapter.HairDryer;
import com.company.design.singleton.AClazz;
import com.company.design.singleton.BClazz;
import com.company.design.singleton.SocketClient;
public class Main {
public static void main(String[] args) {
/*
AClazz aClazz = new AClazz();
BClazz bClazz = new BClazz();
SocketClient aClient = aClazz.getSocketClient();
SocketClient bClient = bClazz.getSocketClient();
System.out.println("두개의 객체가 동일한가?");
System.out.println(aClient.equals(bClient));
*/
HairDryer hairDryer = new HairDryer();
connect(hairDryer);
Cleaner cleaner = new Cleaner();
connect(cleaner);
}
// 콘센트
public static void connect(Electronic110V electronic110V) {
electronic110V.powerOn();
}
}
package com.company.design.adapter;
public class SocketAdapter implements Electronic110V{
private Electronic220V electronic220V;
public SocketAdapter(Electronic220V electronic220V) {
this.electronic220V = electronic220V;
}
@Override
public void powerOn() {
electronic220V.connect();
}
}
package com.company.design;
import com.company.design.adapter.*;
import com.company.design.singleton.AClazz;
import com.company.design.singleton.BClazz;
import com.company.design.singleton.SocketClient;
public class Main {
public static void main(String[] args) {
/*
AClazz aClazz = new AClazz();
BClazz bClazz = new BClazz();
SocketClient aClient = aClazz.getSocketClient();
SocketClient bClient = bClazz.getSocketClient();
System.out.println("두개의 객체가 동일한가?");
System.out.println(aClient.equals(bClient));
*/
HairDryer hairDryer = new HairDryer();
connect(hairDryer);
Cleaner cleaner = new Cleaner();
//connect(cleaner);
Electronic110V adapter = new SocketAdapter(cleaner);
connect(adapter);
AirConditiional airConditiional = new AirConditiional();
//connect(airConditiional);
Electronic110V airAdapter = new SocketAdapter(airConditiional);
connect(airAdapter);
}
// 콘센트
public static void connect(Electronic110V electronic110V) {
electronic110V.powerOn();
}
}