October 2018
Intermediate to advanced
370 pages
9h 15m
English
The factory method pattern is used to make the process of object creation more abstract by using the regular method of a special class instead of a constructor. This approach allows us to instantiate an object of a certain subtype at runtime. The following UML diagram shows the organization of classes and interfaces according to this pattern:

The preceding diagram contains the Mercedes class, which implements the Car interface. The CarFactory class is responsible for creating new instances of the Car type.
The implementation may look as follows:
class CarFactory { fun createCar(brand: Brand): Car { return when(brand) { Brand ...
Read now
Unlock full access