Handling creating of concrete types with Factory method
Factory Method Is a pattern of type creational that delegates the construction of objects to an interface. The interface has a method that return a type of specific object.
Problem The company TransportPassengers has to transport many passengers after your workday.
Solution First of all, we have to create our factory:
func GetTransportType(quPassengers int) (product.ITransport, error) { if quPassengers >= 1 && quPassengers <=5 { return concrete.NewTaxi(), nil } if quPassengers >= 6 && quPassengers <=15 { return concrete.