December 2018
Intermediate to advanced
500 pages
12h 19m
English
A factory is an object that is used to create other objects. We looked at the preceding reservation interface. Essentially, it is an association between an item for sale and a user who bought it, along with some metadata such as dates and so on, and there will be multiple types of reservation. So, how does the client code create a reservation without knowing about implementation classes such as HotelReservationImpl?
In a factory method pattern, a helper method (or function) is defined, to enable object creation without knowing the implementation class details. For example, in the case of reservation, the simple factory can be this:
func NewReservation(vertical, reservationDate string) Reservation { switch(vertical) { case "flight": ...Read now
Unlock full access