public class AbstractFactoryDesignPattern {
public static void main(String[] args) {
Cellphone cellphone = new HuaWeiFactory().createCellphone();
cellphone.display();
}
}
interface Factory {
Cellphone createCellphone();
Computer createComputer();
}
class HuaWeiFactory implements Factory {
@Override
public Cellphone createCellphone() {
return new HuaweiCellphone();
}
@Override
public Computer createComputer() {
return new HuaweiComputer();
}
}
class XiaoMiFactory implements Factory{
@Override
public Cellphone createCellphone() {
return new XiaoMiCellphone();
}
@Override
public Computer createComputer() {
return new XiaoMiComputer();
}
}
interface Cellphone {
void display();
}
interface Computer {
void display();
}
class HuaweiCellphone implements Cellphone {
@Override
public void display() {
System.out.println("This is HuaWeiCellphone");
}
}
class XiaoMiCellphone implements Cellphone {
@Override
public void display() {
System.out.println("This is XiaoMiCellphone");
}
}
class HuaweiComputer implements Computer {
@Override
public void display() {
System.out.println("This is HuaWeiComputer");
}
}
class XiaoMiComputer implements Computer {
@Override
public void display() {
System.out.println("This is XiaoMiComputer");
}
}