I'm learning design patterns now and reading defferent resources for every pattern. I have a question about pattern Abstract Factory. I read about two ways of realization this. I'll write using this factories, withour realization. For example, I took making different doors.
First way. We have common class for Door Factory, which consists different methods for making different types of doors (which returns appropriate class of door):
$doorFactory = new DoorFactory();
$door1 = $doorFactory->createWoodDoor();
$doorFactory = new DoorFactory();
$door2 = $doorFactory->createSteelDoor();
Second way. We have parent class DoorFactory and extends classes for WoodDoorFactory and SteelDoorFactory. This classes realises same method createDoor (and return appropriate class of Door)
$woodDoorFactory = new WoodDoorFactory();
$door1 = $woodDoorFactory->createDoor();
$steelDoorFactory = new SteelDoorFactory();
$door2 = $steelDoorFactory->createDoor();
How you think, which way more optimal and canonical?
Aucun commentaire:
Enregistrer un commentaire