What it is good for?

As with other factories, the details of object creation are hidden. This means that if we change the way a specific instance has to be created, we would have to change only the factory methods that create it (this might involve a lot of creators though, depending on the design). The factory method allows us to use the abstract version of a class and defer the object creation to subclasses.

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.