Factory creates objects. The clients who use the factory can focus on other behavior. So the object creation delegated to another object.
Factory Object
Benefits: if there are multiple clients that want to instantiate the same set of classes, then by using a Factory object, you have cut out redundant code and made software easier to modify. Means if need a change of object creation, then have to modify just a factory instead of every client and it’s calling coding to an interface, not an implementation.
Factory:
public class CarFactory(){
public Car createCar(string carType) {
Car car;
if(carType.Equals("sport")){
car = new SportCar();
}
else if(carType.Equals("city")){
car = new CityCar();
}
return car;
}
}




%20Attributes/Intro%20illities.png?raw=true)
%20Attributes/ScaleUpScaleDown.png?raw=true)
