Other factory design patterns

There are some different variations of the factory design patterns. In all cases, though, the purpose is generally the same—hide creation complexity. In the next subsections, we will briefly mention two of the other factory design patterns: static factory and simple factory.

The static factory

The static factory could be represented as a static method, which is a part of the base class. It is called to create concrete instances, which extend the base class. One of the biggest drawbacks here, however, is that if another extension of the base class is added, the base class (because of the static method) also has to be edited. Let's show a simple example from the world of the animals:

trait Animal class Bird extends Animal ...

Get Scala Design Patterns 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.