Hi all,
Im having trouble getting my head around the concept of the factory design pattern. As far as i understand its to allow calling code not to have to worry about how an individual object is instantiated, simply to know that it will implement a particular interface.
I cant see how this saves any code though.
for instance, if i had 3 types of vehicle
lorry, car, van
and i created a class for each of them, i could just use a switch statement. Whereas with the examples of factory classes ive seen so far, i could have an interface:
Interface vehicle {
method drive();
}
and then a class:
Class vehiclefac implements vehicle {
method createvehicle(type) {
// choose car type and return
}
}
i still need to use a switch statement to pick my type of vehicle, further to this, if i want to add new cars, i still have to add them to the end of the switch statement and create an appropriate sub class to implement them.
If someone can clear up what im not getting id be very grateful, examples in python especially appreciated.