Hızlı yanıt: kod örneği
stackoverflow.com abstract-factory-design-pattern-use
For your example, yes you are right factory pattern can replace abstract factory pattern.Abstract factory makes sense when you need to create different products of same family without actully knowing the family (Volvo or Audi).I believe you can image same things for the Volvo.Now assume that we have a class that builds a and this does not care whether it is an Audi or Volvo.Now our builder class can work without knowing the actual brand which makes the builder class conforming to the Open/Closed Principle. If there is a third brand comes in the future our builder class will still be able to build that car without needing to change single line of code. It is opened to extension but closed to change thanks to the abstract factory..
interface Car {}interface Engine {}interface Gear {}interface ICarFactory { Car createCar(); Engine createEngine(); Gear createGear();}class AudiCar implements Car {}class AudiEngine implements Engine {}class AudiGear implements Gear {}class AudiFactory implements ICarFactory { public Car createCar() { return new AudiCar(); } public Engine createEngine() { return new AudiEngine(); } public Gear createGear() { return new AudiGear(); }}
Car
class CarBuilder { public static Car buildCar(ICarFactory factory) { Car car = factory.createCar(); car.setEngine(factory.createEngine()); car.setGear(factory.createGear()); return car; }}