package com.imust.gof.factory.factorymethod;
publicclassAudiFactoryimplementsCarFactory{@Overridepublic Car createCar() {
returnnew Audi();
}
}
package com.imust.gof.factory.factorymethod;
publicclassBydFactoryimplementsCarFactory{@Overridepublic Car createCar() {
returnnew Byd();
}
}
package com.imust.gof.factory.factorymethod;
publicclass Client {
publicstaticvoidmain(String[] args) {
Car audi = new AudiFactory().createCar();
Car byd = new BydFactory().createCar();
audi.run();
byd.run();
}
}